]> gitweb.factorcode.org Git - factor.git/blob - basis/random/unix/unix.factor
ffddde9f5b465902e7e481f4dcf93b94144e0630
[factor.git] / basis / random / unix / unix.factor
1 ! Copyright (C) 2008 Doug Coleman
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.c-types io io.files kernel namespaces random
4 io.encodings.binary init accessors system destructors
5 hints math ;
6 IN: random.unix
7
8 TUPLE: unix-random reader ;
9
10 : <unix-random> ( path -- random )
11     binary <file-reader> unix-random boa ;
12
13 M: unix-random dispose reader>> dispose ;
14
15 M: unix-random random-bytes* ( n tuple -- byte-array )
16     reader>> stream-read ;
17 HINTS: M\ unix-random random-bytes* { fixnum unix-random } ;
18
19 [
20     "/dev/random" <unix-random> &dispose secure-random-generator set-global
21     "/dev/urandom" <unix-random> &dispose system-random-generator set-global
22 ] "random.unix" add-startup-hook