Re: 32-bit random numbers
- Posted by "Juergen Luethje" <j.lue at gmx.de> Jul 11, 2004
- 587 views
Hi Igor, you wrote: >> From: Juergen Luethje >> Sent: 9 jul 2004 y. 0:48 >> >> Ricardo Forno wrote: >> >>> The resulting distributions are good, >>> but there is a problem. >>> As rand(power(2, 30) -1) can generate >>> only 2^30 - 1 different numbers, no matter >>> what you do with these numbers, you will >>> get possibly only 2^30 - 1 >>> different numbers between 1 and 2^32, >>> and so you will never get one of the >>> remaining 2^32 - 2^30 numbers, or 3/4ths >>> of the total possibilities. >> >> I see. >> Thank you for this important information, Ricardo! >> >> [snipped old text] > > > I see your and can not sleep > Dont be or better Don't worry! I'm sleeping very good, and I hope that you do so, too. > Try please the next one RNG: > > }}} <eucode> > > constant K = 1073741823 -- max EU integer > function rand_atom(integer N) > return K * (rand(N) - 1) + rand(K) - 1 > end function > > </eucode> {{{ > > A short explanation. > > The (rand(N) - 1) part gives the random number > of each next standard flat range. > Say, if N = 1, then next output result will be > rand(K) - 1, i.e. from the normal EU range. > If N = 2, then output result will be: > > a. rand(K) - 1 > > or > > b. K + rand(K) - 1 > > The probability of a or b cases is 1/2, so, > the output result will has the flat range 0 .. K-1 > or K + 0 .. K + K - 1, i.e. 0 .. K-1 .. K .. K + K - 1, > i.e. 0 .. K + K - 1 with discrete flat distribution, > which has step = 1 -- all possible integer numbers. > > Well, if N = 3, then (rand(N) - 1) will be 2 or 1 or 0 > with probability 1/3 of each case. > > So, the output result will have > 0 .. K-1 .. K .. K+K-1 .. K+K .. K+K+K - 1 range > with flat distribution and step = 1 > > And so on. > > It seems to be correct, no? I don't know. It has already been said, that it's not beneficial to combine successive results of rand(). I'm afraid it's all a bit over my head. Things concerning randomness are rather difficult IMHO. Anyway, thanks Igor! > The question is - what maximum N will give > still integer atoms on output - not EU integer type, > but inner EU integer atoms. > > Regards, > Igor Kachan > kinz at peterlink.ru Regards, Juergen