]> gitweb.factorcode.org Git - factor.git/commitdiff
random: speed up uniform-random-float.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 27 Feb 2013 22:40:56 +0000 (14:40 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 27 Feb 2013 22:40:56 +0000 (14:40 -0800)
basis/random/random.factor

index 7d2bfc55a86b7791f3904d9ef1c16e875809b7e2..9eb914d3688bc870fea71af132f020ca38c045fe 100644 (file)
@@ -28,7 +28,8 @@ M: object random-bytes* ( n tuple -- byte-array )
 
 HINTS: M\ object random-bytes* { fixnum object } ;
 
-M: object random-32* ( tuple -- r ) 4 swap random-bytes* be> ;
+M: object random-32* ( tuple -- r )
+    4 swap random-bytes* c:uint deref ;
 
 ERROR: no-random-number-generator ;
 
@@ -121,7 +122,7 @@ ERROR: too-many-samples seq n ;
 <PRIVATE
 
 : (uniform-random-float) ( min max obj -- n )
-    [ 4 4 ] dip [ random-bytes* c:uint deref >float ] curry bi@
+    [ random-32* ] keep random-32* [ >float ] bi@
     2.0 32 ^ * +
     [ over - 2.0 -64 ^ * ] dip
     * + ; inline