factor/extra/io/streams/random/random.factor

28 lines
761 B
Factor
Raw Normal View History

! Copyright (C) 2010 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: destructors io io.encodings.binary io.files
2013-05-07 09:18:50 -04:00
io.streams.limited kernel random random.private sequences
sequences.private ;
IN: io.streams.random
TUPLE: random-stream ;
C: <random-stream> random-stream
M: random-stream stream-element-type drop +byte+ ;
M: random-stream stream-read-unsafe
2013-05-06 11:35:03 -04:00
drop [ dup random-bytes ] [ 0 swap copy-unsafe ] bi* ;
2013-05-06 11:35:03 -04:00
M: random-stream stream-read1 drop 256 random-integer ;
M: random-stream stream-read-partial-unsafe stream-read-unsafe ;
M: random-stream dispose drop ;
INSTANCE: random-stream input-stream
: random-file ( n path -- )
[ <random-stream> swap limit-stream ]
[ binary <file-writer> ] bi* stream-copy ;