]> gitweb.factorcode.org Git - factor.git/commitdiff
io.random: adding "random-file".
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 26 Oct 2012 04:40:43 +0000 (21:40 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 26 Oct 2012 04:40:43 +0000 (21:40 -0700)
extra/io/random/random.factor

index 47abdec2ed1e3e48e06ad7aa0143ac3f6a847787..30559196418a237617c7714fa2e8171ef7d1ee1f 100644 (file)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2012 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: combinators fry io kernel locals math math.order random
-sequences sequences.private ;
+USING: combinators destructors fry io io.encodings.binary
+io.files io.streams.limited io.streams.random kernel locals
+math math.order random sequences sequences.private ;
 
 IN: io.random
 
@@ -26,3 +27,10 @@ PRIVATE>
             r n < [ line r accum set-nth-unsafe ] when
         ] if
     ] each-numbered-line accum ;
+
+: random-file ( n path -- )
+    [
+        [ <random-stream> swap limit-stream ]
+        [ binary <file-writer> ] bi*
+        [ &dispose ] bi@ stream-copy
+    ] with-destructors ;