On 2006-05-30, Oliver Wong <owong@castortech.com> wrote:[color=blue]
>[color=green]
>> 'no', then can anybody tell me what PRNG is behind Sun's version
>> of Math.random()?[/color]
>
> See
http://java.sun.com/j2se/1.5.0/docs/...il/Random.html[/color]
Hmm... so if I understand things correctly, the pseudo-random
numbers produced by Random.nextDouble() are the same as the ones
produced by Math.random() and the underlying algorithm is the one
as specified in
http://java.sun.com/j2se/1.5.0/docs/...ml#nextDouble()
namely
public double nextDouble() {
return (((long)next(26) << 27) + next(27))
/ (double)(1L << 53);
}
Looking at Random.next() then tells me that the PRNG used here is a linear
congruential pseudorandom number generator, as defined by D. H. Lehmer and
described by Donald E. Knuth in The Art of Computer Programming, Volume 2:
Seminumerical Algorithms, section 3.2.1
So am I correct if I say that the Java standard specifies the above PRNG as the PRNG to use when implementing Math.random() ?
Bart
--
"Share what you know. Learn what you don't."