Re: random real number between 0 (inclusive) and 1 (inclusive)
Patricia Shanahan wrote:
Piotr Kobzda wrote:
[...]
I still have some doubts, I don't like "rand.nextDouble()*MILTIPLIER"
part -- I've a feeling it somehow favors small doubles, but I may be
wrong, so never mind...
Take a look at the nextDouble code. It works by collecting a total of 53
bits from next(26) and next(27), concatenating them to form a double in
the range 0 through MULTIPLIER-1, and then double precision dividing the
result by MULTIPLIER. The multiplication just recovers the uniformly
distributed [0,MULTIPLIER) long.
OK, you right -- my mistake in analyzing... However, there is no need
for that (long) -> (double) -> (long) conversion, which is 1:1 in this
case.
And that's what my recent implementation is avoiding. There is just one
slight difference more (making it almost the same as was your initial
suggestion), additional bit from the generator's sequence is used to
make the result duly ranged for each nextInclusiveDouble() call. I'm
just not sure, if it is really correct now? Simply, not sure if a
"jumping" from last result is enough to prevent us from non-uniform
distribution of the resulting sequence. Do you think it's still correct?
piotr