]> gitweb.factorcode.org Git - factor.git/commitdiff
io.random: adding a "random-line" word.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 23 Oct 2012 22:24:03 +0000 (15:24 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 23 Oct 2012 22:24:03 +0000 (15:24 -0700)
extra/io/random/random.factor [new file with mode: 0644]

diff --git a/extra/io/random/random.factor b/extra/io/random/random.factor
new file mode 100644 (file)
index 0000000..5b8d022
--- /dev/null
@@ -0,0 +1,16 @@
+! Copyright (C) 2012 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: io kernel math random ;
+
+IN: io.random
+
+<PRIVATE
+
+: ?replace ( old new n -- old/new )
+    random zero? [ nip ] [ drop ] if ;
+
+PRIVATE>
+
+: random-line ( -- line/f )
+    f 1 [ swap [ ?replace ] [ 1 + ] bi ] each-line drop ;