1 ! Copyright (C) 2010 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: destructors io io.encodings.binary io.files
4 io.streams.limited kernel random random.private
10 C: <random-stream> random-stream
12 M: random-stream stream-element-type drop +byte+ ;
14 M: random-stream stream-read-unsafe
15 drop [ dup random-bytes ] [ 0 swap copy-unsafe ] bi* ;
17 M: random-stream stream-read1 drop 256 random-integer ;
19 M: random-stream stream-read-partial-unsafe stream-read-unsafe ;
21 M: random-stream dispose drop ;
23 INSTANCE: random-stream input-stream
25 : random-file ( n path -- )
26 [ <random-stream> swap limit-stream ]
27 [ binary <file-writer> ] bi* stream-copy ;