]> gitweb.factorcode.org Git - factor.git/blob - basis/random/unix/unix.factor
599cd5e0ad6b3cbc03e1015e3eac9c324935ef5b
[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 ;
5 IN: random.unix
6
7 TUPLE: unix-random reader ;
8
9 : <unix-random> ( path -- random )
10     binary <file-reader> unix-random boa ;
11
12 M: unix-random random-bytes* ( n tuple -- byte-array )
13     reader>> stream-read ;
14
15 os openbsd? [
16     [
17         "/dev/srandom" <unix-random> secure-random-generator set-global
18         "/dev/arandom" <unix-random> system-random-generator set-global
19     ] "random.unix" add-init-hook
20 ] [
21     [
22         "/dev/random" <unix-random> secure-random-generator set-global
23         "/dev/urandom" <unix-random> system-random-generator set-global
24     ] "random.unix" add-init-hook
25 ] if