factor/extra/random/unix/unix.factor

22 lines
600 B
Factor
Raw Normal View History

2008-03-19 17:18:03 -04:00
USING: alien.c-types io io.files io.nonblocking kernel
2008-03-27 07:27:36 -04:00
namespaces random io.encodings.binary singleton init
2008-03-28 23:10:01 -04:00
accessors ;
2008-03-19 17:18:03 -04:00
IN: random.unix
2008-03-28 23:10:01 -04:00
TUPLE: unix-random path ;
C: <unix-random> unix-random
2008-03-19 17:18:03 -04:00
: file-read-unbuffered ( n path -- bytes )
over default-buffer-size [
binary <file-reader> [ read ] with-stream
] with-variable ;
2008-03-28 23:10:01 -04:00
M: unix-random random-bytes* ( n tuple -- byte-array )
path>> file-read-unbuffered ;
2008-03-19 17:18:03 -04:00
2008-03-28 23:10:01 -04:00
[
"/dev/random" <unix-random> secure-random-generator set-global
"/dev/urandom" <unix-random> insecure-random-generator set-global
] "random.unix" add-init-hook