Another Milestone, 128 posts and I still haven’t been kicked off the internet due to lack of lulz. SUCCESS!
Now onto business. I wrote that 3d program to get my fingers wet with OpenGL(yet again) and to test out the Marsaglia effect, where random numbers become not-so random when graphed in 3D.
Interesting links:
Ben had a stroke of genius(and also a stroke, but Ill save that for another post) by suggesting I multiply two contiguous random numbers in the Microsoft random number set together and then modulo that by RANDMAX. It produced the following.

Pretty good eh? I couldn’t construct a visualization with a reoccurring pattern and the numeric series passed a few of the Die Hard tests that I implemented in my program. I thought it was fool proof until I realized that you could attack this based on the flaws in the initial PRNG. After all, Seq[t]*Seq[t+1] only requires you to break that weak random number generator.
After collecting a few other random number lists(including QBASIC’s random sequence), I started looking into academic PRNG algorithms and as it turns out, there are quite a few simple to implement ones. Here is ‘xor and shift’ designed by George Marsaglia:
Here is an example with k=5, period about 2^160,
one of the fastest long period RNGs, returns more than
120 million random 32-bit integers/second (1.8MHz CPU),
seems to pass all tests:
int x=123456789,y=362436069,z=521288629,w=88675123,v=886756453;
/* replace default x,y,z,w,v with five random seed values in calling program */
int xorshift() {
int t;
t=(x^(x>>7));
x=y;
y=z;
z=w;
w=v;
v=(v^(v<<6))^(t^(t<<13));
return (y+y+1)*v;
}
-geo@stat.fsu.edu
And how well does that PRNG fair?

Hey, that looks exactly like that badPRNG * badPRNG discussed above, in fact the box is in the exact same position which could probably lead to a little bit of confusion. But they are completely different, one was generated by multiplying two predictable positions of a bad PRNG together -thus providing a thin veil of randomness - and the other was produced by an actually ‘good’ PRNG.
I probably don’t need to explain the ramifications of a poor random number generator as my audience is mostly tech savvy[1]; and I also shouldn’t have to explain how simple the xorshift algorithm above is, and yet Microsoft decided to go with ’something else’. Recently a bug was discovered in Nmap where the random host generation[2] would start duplicating IP’s after ~500 and would reach 50% duplication around ~1000. The problem Turns out to be Microsoft using a legacy PRNG for their standard c/c++ rand() and a ‘better’ PRNG for their proprietary rand_s().
Alas, this isn’t an anti-Microsoft rant, and later next week I will be putting Linux, IRIX, and possibly others to the same task.
Until then.
[1] My audience consists of my friends, random people from the Google summer of code mailing list, a Godaddy employee, and my father - who doesn’t understand a thing I write about.
[2] Thread here. If your interested in the math side of things keep reading this thread, Kris Katterjohn, Jah, and Brandon Enright all post extremely insightful comments