Ike said:
Any idea using Math.random(), how long it takes to start to cycle? I'm
running upwards of ten million iterations at a crack, using Math.random()
on
each itreration and am wondering if this is actually random enough for my
purposes. Thanks, Ike
Math.random() internally uses the java.util.Random class. From the
documentation for java.util.Random:
<quote>
The class uses a 48-bit seed, which is modified using a linear congruential
formula. (See Donald Knuth, The Art of Computer Programming, Volume 2,
Section 3.2.1.)
</quote>
So do some research to try to calculate what the period is.
Also, the behaviour of Random.nextDouble() (which is what Math.random()
uses), has changed recently.
<quote>
In early versions of Java, the result was incorrectly calculated as:
return (((long)next(27) << 27) + next(27))
/ (double)(1L << 54);
This might seem to be equivalent, if not better, but in fact it introduced a
large nonuniformity because of the bias in the rounding of floating-point
numbers: it was three times as likely that the low-order bit of the
significand would be 0 than that it would be 1!
</quote>
That might affect your answer as well.
- Oliver