]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/random/random.factor
basis: use lint.vocabs tool to trim using lists
[factor.git] / basis / random / random.factor
index 2584412bcd06ed799e073f7857d22b881a34e2f5..e21a7f4d74b12bc70a406467757dd19840671b3b 100644 (file)
@@ -1,11 +1,10 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien.data arrays assocs byte-arrays
-byte-vectors combinators combinators.short-circuit fry
-hashtables hashtables.private hash-sets hints io.backend
-io.binary kernel locals math math.bitwise math.constants
-math.functions math.order math.ranges namespaces sequences
-sequences.private sets summary system typed vocabs ;
+combinators combinators.short-circuit hash-sets hashtables
+hashtables.private kernel math math.bitwise math.constants
+math.functions math.order namespaces sequences sequences.private
+sets summary system vocabs ;
 QUALIFIED-WITH: alien.c-types c
 QUALIFIED-WITH: sets sets
 IN: random
@@ -14,12 +13,12 @@ SYMBOL: system-random-generator
 SYMBOL: secure-random-generator
 SYMBOL: random-generator
 
-GENERIC# seed-random 1 ( obj seed -- obj )
+GENERIC#: seed-random 1 ( obj seed -- obj )
 GENERIC: random-32* ( obj -- n )
 GENERIC: random-bytes* ( n obj -- byte-array )
 
 M: object random-bytes*
-    [ integer>fixnum-strict [ <byte-array> ] keep ] dip
+    [ integer>fixnum-strict [ (byte-array) ] keep ] dip
     [ over 4 >= ] [
         [ 4 - ] dip
         [ random-32* 2over c:int c:set-alien-value ] keep
@@ -35,9 +34,9 @@ ERROR: no-random-number-generator ;
 M: no-random-number-generator summary
     drop "Random number generator is not defined." ;
 
-M: f random-bytes* ( n obj -- * ) no-random-number-generator ;
+M: f random-bytes* no-random-number-generator ;
 
-M: f random-32* ( obj -- * ) no-random-number-generator ;
+M: f random-32* no-random-number-generator ;
 
 : random-32 ( -- n )
     random-generator get random-32* ;
@@ -71,14 +70,14 @@ PRIVATE>
 : next-power-of-2-bits ( m -- numbits )
     dup 2 <= [ drop 1 ] [ 1 - log2 1 + ] if ; inline
 
-:: ((random-integer)) ( m obj -- n )
+:: random-integer-loop ( m obj -- n )
     obj random-32* 32 m next-power-of-2-bits 32 - [ dup 0 > ] [
         [ 32 shift obj random-32* + ] [ 32 + ] [ 32 - ] tri*
     ] while drop [ m * ] [ neg shift ] bi* ; inline
 
-GENERIC# (random-integer) 1 ( m obj -- n )
-M: fixnum (random-integer) ( m obj -- n ) ((random-integer)) ;
-M: bignum (random-integer) ( m obj -- n ) ((random-integer)) ;
+GENERIC#: (random-integer) 1 ( m obj -- n )
+M: fixnum (random-integer) random-integer-loop ;
+M: bignum (random-integer) random-integer-loop ;
 
 : random-integer ( m -- n )
     random-generator get (random-integer) ;
@@ -105,7 +104,7 @@ M: hashtable random
         [ array-nth ] [ [ 1 + ] dip array-nth ] 2bi 2array
     ] if-zero ;
 
-M: unordered-set random members random ;
+M: sets:set random members random ;
 
 M: hash-set random
     dup cardinality [ drop f ] [
@@ -128,7 +127,7 @@ ERROR: too-many-samples seq n ;
 
 : sample ( seq n -- seq' )
     2dup [ length ] dip < [ too-many-samples ] when
-    [ [ length iota >array ] dip [ randomize-n-last ] keep tail-slice* ]
+    [ [ length <iota> >array ] dip [ randomize-n-last ] keep tail-slice* ]
     [ drop ] 2bi nths-unsafe ;
 
 : delete-random ( seq -- elt )