diff --git a/basis/random/random-tests.factor b/basis/random/random-tests.factor index f22b02a147..3bbcd943be 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 math.statistics ; +USING: random sequences tools.test kernel math math.constants +math.functions sets grouping random.private math.statistics ; IN: random.tests [ 4 ] [ 4 random-bytes length ] unit-test @@ -76,3 +76,16 @@ IN: random.tests 50000 [ 2 3 laplace-random-float ] replicate [ mean 2 .2 ~ ] [ std 2 sqrt 3 * .2 ~ ] bi ] unit-test + +{ t t } +[ + 50000 [ 12 rayleigh-random-float ] replicate + [ mean pi 2 / sqrt 12 * .2 ~ ] + [ std 2 pi 2 / - sqrt 12 * .2 ~ ] bi +] unit-test + +{ t t } +[ + 50000 [ 3 4 logistic-random-float ] replicate + [ mean 3 .2 ~ ] [ std pi 4 * 3 sqrt / .2 ~ ] bi +] unit-test diff --git a/basis/random/random.factor b/basis/random/random.factor index cdce8e4afa..a13f4065d7 100644 --- a/basis/random/random.factor +++ b/basis/random/random.factor @@ -242,6 +242,18 @@ ERROR: too-many-samples seq n ; : inv-gamma-random-float ( shape scale -- n ) recip gamma-random-float recip ; +: rayleigh-random-float ( mode -- n ) + random-unit log -2 * sqrt * ; + +: gumbel-random-float ( loc scale -- n ) + random-unit log neg log * - ; + +: logistic-random-float ( loc scale -- n ) + random-unit dup 1 swap - / log * + ; + +: power-random-float ( alpha -- n ) + [ random-unit log exp 1 swap - ] dip recip ^ ; + { { [ os windows? ] [ "random.windows" require ] } { [ os unix? ] [ "random.unix" require ] }