]> gitweb.factorcode.org Git - factor.git/commitdiff
random: support random on sets.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 5 Oct 2012 22:35:22 +0000 (15:35 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 5 Oct 2012 22:35:22 +0000 (15:35 -0700)
basis/random/random.factor

index 2bf65648b93b9c30f8fb132245e3d14238c6327d..5c3992dd5be7a15c77043d1447d97f14931663e5 100644 (file)
@@ -2,11 +2,12 @@
 ! 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 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 ;
+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 ;
 QUALIFIED-WITH: alien.c-types c
+QUALIFIED-WITH: sets sets
 IN: random
 
 SYMBOL: system-random-generator
@@ -83,6 +84,10 @@ M: hashtable random
         [ array-nth ] [ [ 1 + ] dip array-nth ] 2bi 2array
     ] if-zero ;
 
+M: sets:set random members random ;
+
+M: hash-set random table>> random first ;
+
 : randomize-n-last ( seq n -- seq )
     [ dup length dup ] dip - 1 max '[ dup _ > ]
     [ [ random ] [ 1 - ] bi [ pick exchange-unsafe ] keep ]