io.random: adding a "random-line" word.

db4
John Benediktsson 2012-10-23 15:24:03 -07:00
parent 247600df71
commit 50016099a5
1 changed files with 16 additions and 0 deletions

View File

@ -0,0 +1,16 @@
! Copyright (C) 2012 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: io kernel math random ;
IN: io.random
<PRIVATE
: ?replace ( old new n -- old/new )
random zero? [ nip ] [ drop ] if ;
PRIVATE>
: random-line ( -- line/f )
f 1 [ swap [ ?replace ] [ 1 + ] bi ] each-line drop ;