diff --git a/basis/random/random-tests.factor b/basis/random/random-tests.factor index 3854996f33..feebdb26e4 100644 --- a/basis/random/random-tests.factor +++ b/basis/random/random-tests.factor @@ -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 diff --git a/basis/random/random.factor b/basis/random/random.factor index bfd107dbb6..85e4e078c3 100644 --- a/basis/random/random.factor +++ b/basis/random/random.factor @@ -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 ;