byte-arrays byte-vectors combinators fry io.backend io.binary
kernel locals math math.bitwise math.constants math.functions
math.order math.ranges namespaces sequences sequences.private
-sets summary system vocabs ;
+sets summary system vocabs hints typed ;
IN: random
SYMBOL: system-random-generator
M: object random-bytes* ( n tuple -- byte-array )
[ [ <byte-vector> ] keep 4 /mod ] dip
- [ pick '[ _ random-32* 4 >le _ push-all ] times ]
+ [ pick '[ _ random-32* int <ref> _ push-all ] times ]
[
over zero?
- [ 2drop ] [ random-32* 4 >le swap head append! ] if
- ] bi-curry bi* ;
+ [ 2drop ] [ random-32* int <ref> swap head append! ] if
+ ] bi-curry bi* B{ } like ;
+
+HINTS: M\ object random-bytes* { fixnum object } ;
M: object random-32* ( tuple -- r ) 4 swap random-bytes* be> ;
: random-32 ( -- n ) random-generator get random-32* ;
-: random-bytes ( n -- byte-array )
- random-generator get random-bytes* ;
+TYPED: random-bytes ( n: fixnum -- byte-array: byte-array )
+ random-generator get random-bytes* ; inline
<PRIVATE
! Copyright (C) 2008 Doug Coleman
! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types io io.files kernel namespaces random
-io.encodings.binary init accessors system destructors ;
+io.encodings.binary init accessors system destructors
+io.ports hints math ;
IN: random.unix
-TUPLE: unix-random reader ;
+TUPLE: unix-random { reader input-port } ;
: <unix-random> ( path -- random )
binary <file-reader> unix-random boa ;
M: unix-random random-bytes* ( n tuple -- byte-array )
reader>> stream-read ;
+HINTS: M\ unix-random random-bytes* { fixnum unix-random } ;
[
"/dev/random" <unix-random> &dispose secure-random-generator set-global