]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/random/random.factor
Merge OneEyed's patch
[factor.git] / basis / random / random.factor
index 554ed5c96a8d85d807d070aedc6e5cf74daeafa6..ebde3802b458066c58ddd7e948fd7a9ec6346b95 100755 (executable)
@@ -15,12 +15,12 @@ GENERIC: random-32* ( tuple -- r )
 GENERIC: random-bytes* ( n tuple -- byte-array )
 
 M: object random-bytes* ( n tuple -- byte-array )
-    [ [ <byte-vector> ] keep 4 /mod ] dip tuck
+    [ [ <byte-vector> ] keep 4 /mod ] dip
     [ pick '[ _ random-32* 4 >le _ push-all ] times ]
     [
         over zero?
         [ 2drop ] [ random-32* 4 >le swap head over push-all ] if
-    ] 2bi* ;
+    ] bi-curry bi* ;
 
 M: object random-32* ( tuple -- r ) 4 random-bytes* le> ;
 
@@ -52,8 +52,10 @@ PRIVATE>
         [ length random-integer ] keep nth
     ] if-empty ;
 
-: randomize ( seq -- seq' )
-    dup length 1 (a,b] [ dup random pick exchange ] each ;
+: randomize ( seq -- seq )
+    dup length [ dup 1 > ]
+    [ [ random ] [ 1- ] bi [ pick exchange ] keep ]
+    while drop ;
 
 : delete-random ( seq -- elt )
     [ length random-integer ] keep [ nth ] 2keep delete-nth ;