POV-Ray : Newsgroups : povray.general : 2Q's: normal & random Server Time
12 Aug 2024 19:29:47 EDT (-0400)
  2Q's: normal & random (Message 11 to 14 of 14)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Nieminen Mika
Subject: Re: A random trick
Date: 15 Feb 1999 07:37:04
Message: <36c814f0.0@news.povray.org>
Tim Glover <tgl### [at] nettallycom> wrote:
: Most random number generators produce uniform-distributed 
: random numbers, not normally -distributed random numbers.  
: There's an old programmer's trick (at least as old as 
: FORTRAN 4) to approximate normal distributions from uniform
: ones....  take TWO uniform randoms of half the range and add 
: them together to get final value!

  Actually this will not give a normal distribution. If you want a normal
distribution you have to add at least three random numbers or more.

-- 
main(i){char*_="BdsyFBThhHFBThhHFRz]NFTITQF|DJIFHQhhF";while(i=
*_++)for(;i>1;printf("%s",i-70?i&1?"[]":" ":(i=0,"\n")),i/=2);} /*- Warp -*/


Post a reply to this message

From: Tim Glover
Subject: Re: A random trick
Date: 18 Feb 1999 15:35:55
Message: <36CC7A1F.1F61@nettally.com>
Actually, I said "approximate" a normal distribution.  As long 
as you're adding a finite number of uniform numbers together, 
you're only approximating a normal distribution.  Lots of numbers 
just gives a better approximation. My way's approximation is just 
not quite as good as your's <grin>


tgl### [at] nettallycom



Nieminen Mika wrote:
> 
> Tim Glover <tgl### [at] nettallycom> wrote:
> : Most random number generators produce uniform-distributed
> : random numbers, not normally -distributed random numbers.
> : There's an old programmer's trick (at least as old as
> : FORTRAN 4) to approximate normal distributions from uniform
> : ones....  take TWO uniform randoms of half the range and add
> : them together to get final value!
> 
>   Actually this will not give a normal distribution. If you want a normal
> distribution you have to add at least three random numbers or more.
> 
> --
> main(i){char*_="BdsyFBThhHFBThhHFRz]NFTITQF|DJIFHQhhF";while(i=
> *_++)for(;i>1;printf("%s",i-70?i&1?"[]":" ":(i=0,"\n")),i/=2);} /*- Warp -*/


Post a reply to this message

From: Roland Mas
Subject: Re: A random trick
Date: 18 Feb 1999 16:46:43
Message: <m3r9rnbd19.fsf@clodomir.rezel.enst.fr>
Nieminen Mika <war### [at] cctutfi> writes:

>   Actually this will not give a normal distribution. If you want a normal
> distribution you have to add at least three random numbers or more.

Or...  Generate it accurately.  If the numbers you want to generate
are bound to a finite interval [a,b], here is a trick that generates any
distribution on it.

Let f(x) be a function giving the law (density of probability) of your
random number (with a multiplicative constant somewhere).  Multiply it
by a constant so that it is always between 0 and 1.  Then generate a
uniform random variable on the interval you want to reach:
rand_ab()=a+(b-a)*rand(), with rand() being in [0,1].  To construct a
distribution with the law f(x),the algorithm is the following:

- take a number x=rand_ab();
- calculate f(x);
- take a random number in [0,1], y;
- if y<f(x), then keep x, else go back to step 1;
- if you kept x, then this is your final number.

The calculations (I made them some months ago) are quite simple.  They
show that this algorithm gives you any law of probability you may
want.  You can adapt it (via atan() or something like that) to
infinite arrival space, or to add weighted points.

Hope this helps,

Roland.
-- 
Roland Mas

Sauvez les castors, plantez des arbres.


Post a reply to this message

From: Nieminen Mika
Subject: Re: A random trick
Date: 19 Feb 1999 07:14:59
Message: <36cd55c3.0@news.povray.org>
Tim Glover <tgl### [at] nettallycom> wrote:
: Actually, I said "approximate" a normal distribution.  As long 
: as you're adding a finite number of uniform numbers together, 
: you're only approximating a normal distribution.  Lots of numbers 
: just gives a better approximation. My way's approximation is just 
: not quite as good as your's <grin>

  It's a VERY rough approximate, since by adding just two random values
you get a triangle wave distribution. With 3 values it certainly looks a lot
more like a normal distribution.

-- 
main(i){char*_="BdsyFBThhHFBThhHFRz]NFTITQF|DJIFHQhhF";while(i=
*_++)for(;i>1;printf("%s",i-70?i&1?"[]":" ":(i=0,"\n")),i/=2);} /*- Warp -*/


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.