factor/contrib/random-tester/utils.factor

14 lines
394 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
2006-09-29 02:32:48 -04:00
: coin-flip ( -- bool ) 2 random-int zero? ;
: do-one ( seq -- ) nth-rand call ; inline