diff --git a/basis/random/random-tests.factor b/basis/random/random-tests.factor index 3fc4ff80eb..fc545a9247 100644 --- a/basis/random/random-tests.factor +++ b/basis/random/random-tests.factor @@ -1,5 +1,5 @@ USING: random sequences tools.test kernel math math.functions -sets grouping random.private ; +sets grouping random.private math.statistics ; IN: random.tests [ 4 ] [ 4 random-bytes length ] unit-test @@ -33,3 +33,15 @@ IN: random.tests [ ] [ [ 100 random-bytes ] with-system-random drop ] unit-test + +{ t } +[ 50000 [ .15 exponential-random-float ] replicate [ mean ] [ std ] bi .2 ~ ] unit-test + +{ t } +[ 50000 [ 1 exponential-random-float ] replicate [ mean ] [ std ] bi .2 ~ ] unit-test + +{ t t } +[ + 50000 [ 1 3 pareto-random-float ] replicate [ mean ] [ std ] bi + [ 1.5 .3 ~ ] [ 3 sqrt 2 / .3 ~ ] bi* +] unit-test diff --git a/basis/random/random.factor b/basis/random/random.factor index 4c69437244..107c090afd 100644 --- a/basis/random/random.factor +++ b/basis/random/random.factor @@ -127,8 +127,8 @@ ERROR: too-many-samples seq n ; 1. swap / ^ ] dip * ; -: pareto-random-float ( alpha -- n ) - [ random-unit ] dip [ 1. swap / ] bi@ ^ ; +: pareto-random-float ( k alpha -- n ) + [ random-unit ] dip recip ^ /f ; :: (gamma-random-float>1) ( alpha beta -- n ) ! Uses R.C.H. Cheng, "The generation of Gamma