factor/contrib/random-tester/utils.factor

19 lines
469 B
Factor
Raw Normal View History

USING: kernel math sequences namespaces errors hashtables words
arrays parser compiler syntax io optimizer inference tools
prettyprint ;
2006-01-21 01:12:13 -05:00
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 ;
2006-01-21 01:12:13 -05:00
! 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 ;