Make random a generic so it can still be called on integers

db4
Doug Coleman 2010-01-14 11:59:53 -06:00 committed by Slava Pestov
parent 2a9cedd593
commit 52f4a05fad
2 changed files with 6 additions and 2 deletions

View 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

View 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 ;