factor/apps/random-tester/utils.factor

15 lines
397 B
Factor

USING: kernel math sequences namespaces errors hashtables words
arrays parser compiler syntax io optimizer inference tools
prettyprint ;
IN: random-tester
: pick-one ( seq -- elt )
[ length random-int ] keep nth ;
! HASHTABLES
: random-hash-entry ( hash -- key value )
hash>alist pick-one first2 ;
: coin-flip ( -- bool ) 2 random-int zero? ;
: do-one ( seq -- ) pick-one call ; inline