diff --git a/basis/random/random.factor b/basis/random/random.factor index 59a83e3305..4c69437244 100644 --- a/basis/random/random.factor +++ b/basis/random/random.factor @@ -215,6 +215,16 @@ ERROR: too-many-samples seq n ; mu 2pi mod _f cos random-unit 0.5 > [ + ] [ - ] if ] if ; +:: (triangular-random-float) ( low high mode -- n ) + mode low - high low - / :> c! + random-unit :> u! + high low + u c > [ 1. u - u! 1. c - c! swap ] when + [ - u c * sqrt * ] keep + ; + +: triangular-random-float ( low high -- n ) + 2dup + 2 /f (triangular-random-float) ; + { { [ os windows? ] [ "random.windows" require ] } { [ os unix? ] [ "random.unix" require ] }