POV-Ray : Newsgroups : povray.general : 2Q's: normal & random : Re: A random trick Server Time
12 Aug 2024 21:23:52 EDT (-0400)
  Re: A random trick  
From: Roland Mas
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

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