Re: 32-bit random numbers
- Posted by "Igor Kachan" <kinz at peterlink.ru> Jul 06, 2004
- 579 views
Hi again Jurgen, Me wrote: ---------- > From: Igor Kachan <kinz at peterlink.ru> > To: EUforum at topica.com > Subject: Re: 32-bit random numbers > Sent: 6 jul 2004 y. 2:15 > > Hi Juergen, > > ---------- > > From: Juergen Luethje <j.lue at gmx.de> > > To: EUforum at topica.com > > Subject: Re: 32-bit random numbers > > Sent: 6 jul 2004 y. 0:06 > > [snipped] > > > So I have the Mersenne Twister from the archieves, > > getRandInt() from Win32Lib, > > and the stuff discussed here. > > Very nice, thanks again! > > Get one trick more: > > To get the 32 bit rnd flat distribution > you can do the following steps: > > a. Get rnd number in [0,1] range from the EU standard rand() > b. Get rnd number in needed range from [0,1] range. > > It may be done as: > > }}} <eucode> > atom k > k = 1 / 1073741823 -- the biggest EU integer > atom rnd_0_1 > > function rand_0_N(atom N) > rnd_0_1 = k * (rand(1073741823)-1) > return floor(N * rnd_0_1) > end function > > for i=1 to 1000 do > ? 1 + rand_0_N(#FFFFFFFF) -- this distribution > -- is in [1,#FFFFFFFF] range > end for > </eucode> {{{ Yes, it seems to be: for i=1 to 1000 do ? 1 + rand_0_N(#FFFFFFFF - 1) -- this distribution -- is in [1,#FFFFFFFF] range end for ---- Regards, Igor Kachan kinz at peterlink.ru