random: rewrite normal-random-float to be more readable

db4
Joe Groff 2011-09-09 12:42:27 -07:00
parent 40ac81d656
commit 8f6c6e5691
1 changed files with 7 additions and 5 deletions
basis/random

View File

@ -96,12 +96,14 @@ ERROR: too-many-samples seq n ;
[ over - 2.0 -64 ^ * ] dip
* + ; inline
: (cos-random-float) ( -- n )
0. 2. pi * uniform-random-float cos ;
: (log-sqrt-random-float) ( -- n )
0. 1. uniform-random-float log -2. * sqrt ;
: normal-random-float ( mean sigma -- n )
0.0 1.0 uniform-random-float
0.0 1.0 uniform-random-float
[ 2 pi * * cos ]
[ 1.0 swap - log -2.0 * sqrt ]
bi* * * + ;
(cos-random-float) (log-sqrt-random-float) * * + ;
{
{ [ os windows? ] [ "random.windows" require ] }