io.random: adding "random-file".

db4
John Benediktsson 2012-10-25 21:40:43 -07:00
parent 916d912492
commit ca315e7996
1 changed files with 10 additions and 2 deletions

View File

@ -1,8 +1,9 @@
! Copyright (C) 2012 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: combinators fry io kernel locals math math.order random
sequences sequences.private ;
USING: combinators destructors fry io io.encodings.binary
io.files io.streams.limited io.streams.random kernel locals
math math.order random sequences sequences.private ;
IN: io.random
@ -26,3 +27,10 @@ PRIVATE>
r n < [ line r accum set-nth-unsafe ] when
] if
] each-numbered-line accum ;
: random-file ( n path -- )
[
[ <random-stream> swap limit-stream ]
[ binary <file-writer> ] bi*
[ &dispose ] bi@ stream-copy
] with-destructors ;