Random number generators discussion

Random number generators | www.agner.org

Generate ALL float numbers in RNG?
Author:  Date: 2004-06-18 20:43
I know the smallest positive double is 2^-1022.
What I mean is your algorithm can't generate all valid random numbers in [0,1).
Your algorithm is like to generate a binary fixed point number of:


and returns f-1.0. This is equal to random()/2^32 mathematically (with full
scale computation, certainly). The problem is, if random() outputs a small number,
say 127, we can write the output float as this:

1.111111(in binary)x2^-25

The problem here is, the mantissa has only 6 bits. The precision is very bad.
Single precision float format can have 2^22 different numbers in [2^-25,2^-24),
but your program can only gives 2^6 = 64 of them.

You may argue the probability is very low, but with my test,
it hits 2^-27 in less than 30 secons, and hits 0 about 9 times in one hour.
I use your B generator to do the test on a Pentium 4 2GHz CPU.
The smallest positive number your program can give is 2^-32 and I met this
number in the one-hour test. This number will given as the entire mantissa
field equals 0.

thread Generate ALL float numbers in RNG? new - Hangzai Luo - 2004-06-16
last replythread Generate ALL float numbers in RNG? new - Agner - 2004-06-18
last replythread Generate ALL float numbers in RNG? - Hangzai Luo - 2004-06-18
last reply Generate ALL float numbers in RNG? new - Agner - 2004-06-19