From 916d91249263d09156642c3ac6f3980544ef0973 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Thu, 25 Oct 2012 21:37:58 -0700 Subject: [PATCH] io.streams.random: adding @erg's random-stream. --- extra/io/streams/random/authors.txt | 1 + extra/io/streams/random/random.factor | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 extra/io/streams/random/authors.txt create mode 100644 extra/io/streams/random/random.factor diff --git a/extra/io/streams/random/authors.txt b/extra/io/streams/random/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/io/streams/random/authors.txt @@ -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 index 0000000000..191d344930 --- /dev/null +++ b/extra/io/streams/random/random.factor @@ -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 + +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