remove random.backend
							parent
							
								
									89cacd416b
								
							
						
					
					
						commit
						2426fc44bb
					
				| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
USING: vocabs.loader sequences system
 | 
			
		||||
random random.mersenne-twister combinators init
 | 
			
		||||
namespaces ;
 | 
			
		||||
namespaces random.backend ;
 | 
			
		||||
 | 
			
		||||
"random.mersenne-twister" require
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -9,5 +9,6 @@ namespaces ;
 | 
			
		|||
    { [ unix? ] [ "random.unix" require ] }
 | 
			
		||||
} cond
 | 
			
		||||
 | 
			
		||||
! [ [ 32 random-bits ] with-secure-random <mersenne-twister> random-generator set-global ]
 | 
			
		||||
[ millis <mersenne-twister> random-generator set-global ]
 | 
			
		||||
"generator.random" add-init-hook
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,24 +0,0 @@
 | 
			
		|||
! Copyright (C) 2008 Doug Coleman.
 | 
			
		||||
! See http://factorcode.org/license.txt for BSD license.
 | 
			
		||||
USING: alien.c-types kernel math namespaces sequences
 | 
			
		||||
io.backend io.binary combinators system vocabs.loader ;
 | 
			
		||||
IN: random.backend
 | 
			
		||||
 | 
			
		||||
SYMBOL: insecure-random-generator
 | 
			
		||||
SYMBOL: secure-random-generator
 | 
			
		||||
SYMBOL: random-generator
 | 
			
		||||
 | 
			
		||||
GENERIC: seed-random ( tuple seed -- )
 | 
			
		||||
GENERIC: random-32* ( tuple -- r )
 | 
			
		||||
GENERIC: random-bytes* ( n tuple -- bytes )
 | 
			
		||||
 | 
			
		||||
M: object random-bytes* ( n tuple -- byte-array )
 | 
			
		||||
    swap [ drop random-32* ] with map >c-uint-array ;
 | 
			
		||||
 | 
			
		||||
M: object random-32* ( tuple -- n ) 4 random-bytes* le> ;
 | 
			
		||||
 | 
			
		||||
ERROR: no-random-number-generator ;
 | 
			
		||||
 | 
			
		||||
M: f random-bytes* ( n obj -- * ) no-random-number-generator ;
 | 
			
		||||
 | 
			
		||||
M: f random-32* ( obj -- * ) no-random-number-generator ;
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
USING: kernel random math accessors random.backend ;
 | 
			
		||||
USING: kernel random math accessors random ;
 | 
			
		||||
IN: random.dummy
 | 
			
		||||
 | 
			
		||||
TUPLE: random-dummy i ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
USING: kernel math random namespaces random.mersenne-twister
 | 
			
		||||
sequences tools.test random.backend ;
 | 
			
		||||
sequences tools.test ;
 | 
			
		||||
IN: random.mersenne-twister.tests
 | 
			
		||||
 | 
			
		||||
: check-random ( max -- ? )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@
 | 
			
		|||
 | 
			
		||||
USING: arrays kernel math namespaces sequences system init
 | 
			
		||||
accessors math.ranges combinators.cleave new-effects
 | 
			
		||||
random.backend ;
 | 
			
		||||
random ;
 | 
			
		||||
IN: random.mersenne-twister
 | 
			
		||||
 | 
			
		||||
<PRIVATE
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,11 +1,28 @@
 | 
			
		|||
! Copyright (C) 2008 Doug Coleman.
 | 
			
		||||
! See http://factorcode.org/license.txt for BSD license.
 | 
			
		||||
USING: alien.c-types kernel math namespaces sequences
 | 
			
		||||
io.backend io.binary combinators system vocabs.loader
 | 
			
		||||
random.backend random.mersenne-twister init ;
 | 
			
		||||
USE: prettyprint
 | 
			
		||||
io.backend io.binary combinators system vocabs.loader ;
 | 
			
		||||
IN: random
 | 
			
		||||
 | 
			
		||||
SYMBOL: insecure-random-generator
 | 
			
		||||
SYMBOL: secure-random-generator
 | 
			
		||||
SYMBOL: random-generator
 | 
			
		||||
 | 
			
		||||
GENERIC: seed-random ( tuple seed -- )
 | 
			
		||||
GENERIC: random-32* ( tuple -- r )
 | 
			
		||||
GENERIC: random-bytes* ( n tuple -- bytes )
 | 
			
		||||
 | 
			
		||||
M: object random-bytes* ( n tuple -- byte-array )
 | 
			
		||||
    swap [ drop random-32* ] with map >c-uint-array ;
 | 
			
		||||
 | 
			
		||||
M: object random-32* ( tuple -- n ) 4 random-bytes* le> ;
 | 
			
		||||
 | 
			
		||||
ERROR: no-random-number-generator ;
 | 
			
		||||
 | 
			
		||||
M: f random-bytes* ( n obj -- * ) no-random-number-generator ;
 | 
			
		||||
 | 
			
		||||
M: f random-32* ( obj -- * ) no-random-number-generator ;
 | 
			
		||||
 | 
			
		||||
: random-bytes ( n -- r )
 | 
			
		||||
    [
 | 
			
		||||
        dup 4 rem zero? [ 1+ ] unless
 | 
			
		||||
| 
						 | 
				
			
			@ -29,13 +46,3 @@ IN: random
 | 
			
		|||
 | 
			
		||||
: with-secure-random ( quot -- )
 | 
			
		||||
    >r secure-random-generator get r> with-random ; inline
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
    { [ windows? ] [ "random.windows" require ] }
 | 
			
		||||
    { [ unix? ] [ "random.unix" require ] }
 | 
			
		||||
} cond
 | 
			
		||||
 | 
			
		||||
[
 | 
			
		||||
    [ 32 random-bits ] with-secure-random
 | 
			
		||||
    <mersenne-twister> random-generator set-global
 | 
			
		||||
] "random" add-init-hook
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
USING: alien.c-types io io.files io.nonblocking kernel
 | 
			
		||||
namespaces random.backend io.encodings.binary singleton init
 | 
			
		||||
namespaces random io.encodings.binary singleton init
 | 
			
		||||
accessors ;
 | 
			
		||||
IN: random.unix
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,5 @@
 | 
			
		|||
USING: accessors alien.c-types byte-arrays continuations
 | 
			
		||||
kernel windows windows.advapi32 init namespaces
 | 
			
		||||
random.backend ;
 | 
			
		||||
kernel windows windows.advapi32 init namespaces random ;
 | 
			
		||||
IN: random.windows
 | 
			
		||||
 | 
			
		||||
TUPLE: windows-crypto-context handle ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue