]> gitweb.factorcode.org Git - factor.git/commitdiff
math.extras: fix weighted-random by using float random
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 22 Jan 2023 15:34:07 +0000 (07:34 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 22 Jan 2023 15:34:07 +0000 (07:34 -0800)
extra/math/extras/extras.factor

index 1dc7f8ff820350c3fd07f9aa8a229a7fb6797e85..e3ac7af7da9ac0d32d3dbf0315a63d8cf7cc04a8 100644 (file)
@@ -199,7 +199,7 @@ PRIVATE>
     dup sum '[ _ / dup ^ ] map-product ;
 
 : weighted-random ( histogram -- obj )
-    unzip cum-sum [ last random ] [ bisect-left ] bi swap nth ;
+    unzip cum-sum [ last >float random ] [ bisect-left ] bi swap nth ;
 
 : unique-indices ( seq -- unique indices )
     [ members ] keep over dup length <iota>