factor/basis/random/unix/unix.factor

21 lines
644 B
Factor
Raw Normal View History

! Copyright (C) 2008 Doug Coleman
! See http://factorcode.org/license.txt for BSD license.
2008-07-02 16:57:38 -04:00
USING: alien.c-types io io.files kernel namespaces random
io.encodings.binary init accessors system destructors ;
2008-03-19 17:18:03 -04:00
IN: random.unix
2008-07-02 16:57:38 -04:00
TUPLE: unix-random reader ;
2008-03-28 23:10:01 -04:00
2008-07-02 16:57:38 -04:00
: <unix-random> ( path -- random )
binary <file-reader> unix-random boa ;
2008-03-19 17:18:03 -04:00
M: unix-random dispose reader>> dispose ;
2008-03-28 23:10:01 -04:00
M: unix-random random-bytes* ( n tuple -- byte-array )
2008-07-02 16:57:38 -04:00
reader>> stream-read ;
2008-03-19 17:18:03 -04:00
[
"/dev/random" <unix-random> &dispose secure-random-generator set-global
"/dev/urandom" <unix-random> &dispose system-random-generator set-global
] "random.unix" add-startup-hook