]> gitweb.factorcode.org Git - factor.git/commitdiff
Make random a generic so it can still be called on integers
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 14 Jan 2010 17:59:53 +0000 (11:59 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 14 Jan 2010 18:15:35 +0000 (07:15 +1300)
basis/random/random-tests.factor
basis/random/random.factor

index 3854996f33f6a7d9b7b940c900268c20828cd4f7..feebdb26e410fb8551a22d4d4941be96e25f01d6 100644 (file)
@@ -29,7 +29,7 @@ IN: random.tests
 [ { 1 2 } 3 sample ] [ too-many-samples?  ] must-fail-with
 
 [ 3 ] [ { 1 2 3 4 } 3 sample prune length ] unit-test
-[ 99 ] [ 100 99 sample prune length ] unit-test
+[ 99 ] [ 100 iota 99 sample prune length ] unit-test
 
 [ ]
 [ [ 100 random-bytes ] with-system-random drop ] unit-test
index bfd107dbb64772824b5757e79a0c796296bbdd2e..85e4e078c3927e72cfe159f5674775874b9089ae 100644 (file)
@@ -50,7 +50,11 @@ PRIVATE>
 : random-bits* ( numbits -- n )
     1 - [ random-bits ] keep set-bit ;
 
-: random ( seq -- elt )
+GENERIC: random ( obj -- elt )
+
+M: integer random random-integer ;
+
+M: sequence random
     [ f ] [
         [ length random-integer ] keep nth
     ] if-empty ;