>> 'no', then can anybody tell me what PRNG is behind Sun's version
>> of Math.random()?
>
> See http://java.sun.com/j2se/1.5.0/docs/api/java/util/Random.html
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/api/java/util/Random.html#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

Signature
"Share what you know. Learn what you don't."
Oliver Wong - 30 May 2006 22:01 GMT
[...]
> public double nextDouble() {
> return (((long)next(26) << 27) + next(27))
> / (double)(1L << 53);
> }
[...]
> So am I correct if I say that the Java standard specifies the above PRNG
> as the PRNG to use when implementing Math.random() ?
Yes, I think so, or at least one which returns the exact same set of
numbers given the same initial seed.
- Oliver