### 3D scatter plots

I want to create 3D scatter plots of the PRNG's in the C++11 random library for amusement.

With inspiration from the Internet* my current algorithm looks like:

 ```x = random() % max y = random() % max z = random() % max while (do more dots) { Vertex3i(x, y, z) x = y y = z z = random() % max }```

I don't like it, mostly because of the modulo. How should I do things?

* http://www.de-brauwer.be/wiki/wikka.php?wakka=PyOpenGLScatter
Catfish4 wrote:
I don't like it, mostly because of the modulo. How should I do things?

Are the 'things' generating random numbers? If so, take a look at 'Random Number Generation in C++11'[1]
________________________________________________________
[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3551.pdf
 Are the 'things' generating random numbers?

No. Sorry for not being clear enough. (Thanks for the link though, which I will read.)

My question was: what is a better algorithm for generating the 3D points in the scatter plot?
I ask this because by using modulo, information is lost.

So how else can I create the random points for the plot? Should I scale them down by a factor of say 1000 and use double?
Last edited on
 I ask this because by using modulo, information is lost.

This is why I was thinking you where asking about generating randon numbers, std::uniform_real_distribution it what I was thinking as a replacement for the modulo op.
Thanks again for the link. That PDF even exemplified the modulo method I've been using as an anti-pattern. The more you re-learn...

Now the resulting plots are nice. I still don't fully understand what I'm seeing, but I guess herein lies the decay of autumn.

If anybody wants the horrible code (based NeHe Lesson 7, and for Visual Studio 2012), here it is:
http://filebin.ca/x2AEsCM4KmW/Lesson07-scatterplots.zip

I suggest you edit the screen_width and screen_height constants before building.
After that, use the arrow keys to rotate, and Page Up and Page Down to zoom.
Topic archived. No new replies allowed.