factor/contrib/random-tester/utils.factor

23 lines
502 B
Factor
Raw Normal View History

2006-01-21 01:12:13 -05:00
USING: kernel math sequences namespaces errors hashtables words arrays parser
2006-01-27 14:31:50 -05:00
compiler syntax lists io ;
2006-05-17 17:37:37 -04:00
USING: optimizer inference
2006-01-21 01:12:13 -05:00
inspector prettyprint ;
IN: random-tester
2006-01-27 14:31:50 -05:00
: nth-rand ( seq -- elem ) [ length random-int ] keep nth ;
2006-01-21 01:12:13 -05:00
! HASHTABLES
: random-hash-entry ( hash -- key value ) hash>alist nth-rand first2 ;
! ARRAYS
: 4array ( a b c d -- seq ) 2array >r 2array r> append ;
: coin-flip ( -- bool ) 2 random-int 1 = ;
! UNCOMPILABLES
: do-one ( seq -- ) nth-rand call ;