POV-Ray : Newsgroups : povray.advanced-users : Normal distribution : Re: Normal distribution Server Time
28 Jul 2024 18:13:22 EDT (-0400)
  Re: Normal distribution  
From: Chris Johnson
Date: 5 May 2004 21:47:07
Message: <4099991b$1@news.povray.org>
-[You can approximate a normal distribution of numbers...]-
...but this is an inefficient method. The standard method is the Box-Muller
transform, given here in C.

float v1,v2,rsq,fac;
do
{
  v1=rand()*2.0-1.0; v2=rand()*2.0-1.0;
  rsq=v1*v1+v2*v2;
} while (rsq>=1.0 || rsq==0.0)
fac=sqrt(-2.0*log(rsq)/rsq);

This generates two independent normal deviates (v1*fac) and (v2*fac) (with
zero mean and unit variance). The "rand()" function here generates uniform
deviates between 0 and 1.


-[...and dividing the result by n]-
Actually, with this method you need to divide by sqrt(n) if you want to keep
the variance independent of n.

-Chris


Post a reply to this message

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