Gaussian pseudo-random numbers -- math issues

Timothy Miller gandalf at doctorTimothyMiller.com
Sun Oct 26 23:14:39 EDT 2008


Thanks very, very much to Michael, Mark and Mark. (I hope I didn't  
miss anybody.)

This is an excellent start. I think I can take it from here.

Cheers,


Tim Miller


On Oct 22, 2008, at 6:46 PM, Mark Smith wrote:

> Timothy, the only way I could find of doing what you want is called  
> 'the polar form of the Box-Muller transformation'.
>
> Fortunately, it's not as bad as it sounds. :)
>
> I've copied an ADA implementation, and here it is:
>
> function polarBoxMuller pLength, pMean, pSdev
>    put false into useLast
>    repeat pLength
>
>       repeat
>          put ((random(101) - 1) * 0.02) - 1 into x1 -- generate a  
> random number between -1 and +1
>          put ((random(101) - 1) * 0.02) - 1 into x2
>
>          put (x1 * x1) + (x2 * x2) into w
>          if w <= 1 then exit repeat
>       end repeat
>
>       if w <> 0 then put ln(w) * -2 into w -- rev barfs if w is zero
>       if w <> 0 then put sqrt(w) / w into w -- ditto
>
>       put x1 * w into y1
>       put x2 * w into y2
>
>       put pMean + y1 * pSdev & comma after tList
>       put pMean + y2 * pSdev & comma after tList
>    end repeat
>
>    return char 1 to -2 of tList
> end polarBoxMuller
>
> This should give you a comma delimited list of (fairly) normally  
> distributed numbers.
>
> Best,
>
> Mark
>
> ps. I enjoy this sort of thing, so thanks for the question!
>
>



More information about the use-livecode mailing list