From ae276ec22503c9393655ba5f724ba66a76449873 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 7 Dec 2012 09:29:48 -0800 Subject: [PATCH] random: Add poisson-random-float. --- basis/random/random.factor | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/basis/random/random.factor b/basis/random/random.factor index 5c3992dd5b..5571fccd3d 100644 --- a/basis/random/random.factor +++ b/basis/random/random.factor @@ -287,6 +287,12 @@ M: float random [ f ] [ 0.0 swap uniform-random-float ] if-zero ; : power-random-float ( alpha -- n ) [ random-unit log e^ 1 swap - ] dip recip ^ ; +! Box-Muller +: poisson-random-float ( mean -- n ) + [ -1 0 ] dip + [ 2dup < ] + [ [ 1 + ] 2dip [ random-unit log neg + ] dip ] while 2drop ; + { { [ os windows? ] [ "random.windows" require ] } { [ os unix? ] [ "random.unix" require ] }