Faster uniform() in [0.0 - 1.0(
Don
nospam at nospam.com
Tue Nov 23 00:17:21 PST 2010
bearophile wrote:
> Don:
>
>> Since the probability of actually generating a
>> zero is 1e-4000, it shouldn't affect the speed at all <g>.
>
> If bits in double have the same probability then I think there is a much higher probability to hit a zero, about 1 in 2^^63, and I'm not counting NaNs (but it's low enough to not change the substance of what you have said).
Yes, but randomly generated bits doesn't give a uniform distribution.
With a uniform distribution, there should be as much chance of getting
[1-real.epsilon .. 1]
as
[0.. real.epsilon]
But there are only two representable numbers in the first range, and
approx 2^^70 in the second.
Further, there are 2^^63 numbers in the range [0..real.min] which are
all equally likely.
So, if you want a straightforward uniform distribution, you're better
off using [1..2) or [0.5..1) than [0..1), because every possible result
is equally likely.
More information about the Digitalmars-d
mailing list