factor/apps/random-tester/utils.factor

15 lines
397 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
: pick-one ( seq -- elt )
[ length random-int ] keep nth ;
2006-01-27 14:31:50 -05:00
2006-01-21 01:12:13 -05:00
! HASHTABLES
: random-hash-entry ( hash -- key value )
hash>alist pick-one 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 -- ) pick-one call ; inline