]> gitweb.factorcode.org Git - factor.git/commitdiff
io.streams.random: adding @erg's random-stream.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 26 Oct 2012 04:37:58 +0000 (21:37 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 26 Oct 2012 04:37:58 +0000 (21:37 -0700)
extra/io/streams/random/authors.txt [new file with mode: 0644]
extra/io/streams/random/random.factor [new file with mode: 0644]

diff --git a/extra/io/streams/random/authors.txt b/extra/io/streams/random/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/extra/io/streams/random/random.factor b/extra/io/streams/random/random.factor
new file mode 100644 (file)
index 0000000..191d344
--- /dev/null
@@ -0,0 +1,21 @@
+! Copyright (C) 2010 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: destructors io kernel random sequences ;
+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
+    drop [ dup random-bytes ] [ 0 swap copy ] bi* ;
+
+M: random-stream stream-read1 drop 256 random ;
+
+M: random-stream stream-read-partial-unsafe stream-read-unsafe ;
+
+M: random-stream dispose drop ;
+
+INSTANCE: random-stream input-stream