Make random a generic so it can still be called on integers
parent
2a9cedd593
commit
52f4a05fad
|
@ -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
|
||||
|
|
|
@ -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 ;
|
||||
|
|
Loading…
Reference in New Issue