Re: 32-bit random numbers

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hello Ricardo,

You wrote:
----------
> From: Ricardo Forno <rforno at uyuyuy.com>
> To: EUforum at topica.com
> Subject: RE: 32-bit random numbers
> Sent: 7 jul 2004 y. 22:09
> 
> 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.

Yes, the distribution will be discrete, but this is
another question - what precision do you need in your
statistic task and what is precision of your measurements.

But to get the first histogram you need just 50 .. 60
random numbers and may use 10 .. 12 intervals.

To get the maximum number of different random integer
atoms in EU, in floor() range, without thinking about
the real distribution, this is the third question. 

Regards,
Igor Kachan
kinz at peterlink.ru


> Regards.
> ----- Original Message -----
> From: Juergen Luethje <j.lue at gmx.de>
> To: <EUforum at topica.com>
> Sent: Tuesday, July 06, 2004 7:47 PM
> Subject: Re: 32-bit random numbers
> 
> >
> > Hi Igor, you wrote:
> >
> > > Hi again Jurgen,
> > >
> > > Me wrote:
> >
> > <snip>
> >
> > >> 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>
{{{

> >
> > Cool! Why didn't I think of that? smile
> >
> > > 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   ----    blink
> >
> > It seems to me, that your *first* version was correct, wasn't it?
> > For testing, I used N=6:
> >
> > }}}
<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
> >
> > atom N, x, min, max
> >
> > N = 6
> > min = 1 + rand_0_N(N)
> > max = min
> > for i=1 to 1000 do
> >    x = 1 + rand_0_N(N)  -- this distribution is in [1,6] range
> >    if x < min then
> >       min = x
> >    elsif x > max then
> >       max = x
> >    end if
> > end for
> > printf(1, "range [%d,%d]", {min, max})
> > </eucode>
{{{

> >
> > Thanks, Igor!
> >
> > Regards,
> >    Juergen

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu