|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
|
|