BTW!
You should note that your testing methodology is meaningless and the sample size is also far too small - this is not the correct way to test randomness.
I made a simple test script to generate 10MB of random data:
function game() {
var f = OpenRawFile("prng.out", true);
for (var i = 0; i < 10 * 1024 * 1024; i++) {
f.write(CreateByteArrayFromString(String.fromCharCode(Math.random() * 255)));
}
}
Caveats: Math.random returns a floating point number between 0 and 1, but I want raw bytes, so I convert. This probably isn't perfect.
The 'ent' tool is useful for measuring randomness: http://fourmilab.ch/random/
It takes an input file and will run a number of tests.
$ ent prng.out
Entropy = 7.988667 bits per byte.
Optimum compression would reduce the size
of this 10444516 byte file by 0 percent.
Chi square distribution for 10444516 samples is 82493.96, and randomly
would exceed this value less than 0.01 percent of the times.
Arithmetic mean value of data bytes is 127.5418 (127.5 = random).
Monte Carlo value for Pi is 3.155868268 (error 0.45 percent).
Serial correlation coefficient is -0.000395 (totally uncorrelated = 0.0).
We can see that the results are that: the Chi square test shows it isn't truly random (this is to be expected as it is a PRNG) but it does have high entropy, gives a good distribution and low serial correlation. You can check the website for ent for a better explanation of these values.
For comparison, here is the output on 10MB of data from /dev/urandom
$ ent urandom.out
Entropy = 7.999982 bits per byte.
Optimum compression would reduce the size
of this 10485760 byte file by 0 percent.
Chi square distribution for 10485760 samples is 257.28, and randomly
would exceed this value 44.82 percent of the times.
Arithmetic mean value of data bytes is 127.4865 (127.5 = random).
Monte Carlo value for Pi is 3.141253335 (error 0.01 percent).
Serial correlation coefficient is -0.000208 (totally uncorrelated = 0.0).
And the output for /dev/random:
$ ent random.out
Entropy = 7.999983 bits per byte.
Optimum compression would reduce the size
of this 10485760 byte file by 0 percent.
Chi square distribution for 10485760 samples is 245.35, and randomly
would exceed this value 65.65 percent of the times.
Arithmetic mean value of data bytes is 127.5263 (127.5 = random).
Monte Carlo value for Pi is 3.139946419 (error 0.05 percent).
Serial correlation coefficient is -0.000122 (totally uncorrelated = 0.0).
As expected these two have a better chi square distribution as they use hardware entropy sources.
I believe that the version of SM used in Sphere is using a linear congruential generator ripped from Java.
Anyway, a conclusion:
Unless you're doing cryptography in Sphere, the built in Math.random implementation really is good enough.