]> gitweb.factorcode.org Git - factor.git/blob - extra/io/streams/random/random.factor
Switch to https urls
[factor.git] / extra / io / streams / random / random.factor
1 ! Copyright (C) 2010 Doug Coleman.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: destructors io io.encodings.binary io.files
4 io.streams.limited kernel random random.private
5 sequences.private ;
6 IN: io.streams.random
7
8 TUPLE: random-stream ;
9
10 C: <random-stream> random-stream
11
12 M: random-stream stream-element-type drop +byte+ ;
13
14 M: random-stream stream-read-unsafe
15     drop [ dup random-bytes ] [ 0 swap copy-unsafe ] bi* ;
16
17 M: random-stream stream-read1 drop 256 random-integer ;
18
19 M: random-stream stream-read-partial-unsafe stream-read-unsafe ;
20
21 M: random-stream dispose drop ;
22
23 INSTANCE: random-stream input-stream
24
25 : random-file ( n path -- )
26     [ <random-stream> swap limit-stream ]
27     [ binary <file-writer> ] bi* stream-copy ;