cs: fix random-seed
to be compatible with Racket
Fix `random-seed` to set the pseudo-random generator's state to the same state as traditional Racket.
This commit is contained in:
parent
afef3fe900
commit
dd5e517e88
|
@ -90,14 +90,16 @@
|
||||||
(srand-half! s (bitwise-and (bitwise-arithmetic-shift-right x 16) #xFFFF)))
|
(srand-half! s (bitwise-and (bitwise-arithmetic-shift-right x 16) #xFFFF)))
|
||||||
|
|
||||||
(define (srand-half! s x)
|
(define (srand-half! s x)
|
||||||
(let* ([x (random-n! x
|
(let* ([u32+ (lambda (a b)
|
||||||
|
(bitwise-and (+ a b) #xFFFFFFFF))]
|
||||||
|
[x (random-n! x
|
||||||
(- Im1 1)
|
(- Im1 1)
|
||||||
(lambda (z)
|
(lambda (z)
|
||||||
(pseudo-random-generator-x10-set!
|
(pseudo-random-generator-x10-set!
|
||||||
s
|
s
|
||||||
(exact->inexact
|
(exact->inexact
|
||||||
(+ 1 (modulo
|
(+ 1 (modulo
|
||||||
(+ (inexact->exact (pseudo-random-generator-x10 s))
|
(u32+ (inexact->exact (pseudo-random-generator-x10 s))
|
||||||
z)
|
z)
|
||||||
(- Im1 1)))))))]
|
(- Im1 1)))))))]
|
||||||
[x (random-n! x
|
[x (random-n! x
|
||||||
|
@ -106,20 +108,20 @@
|
||||||
(pseudo-random-generator-x11-set!
|
(pseudo-random-generator-x11-set!
|
||||||
s
|
s
|
||||||
(exact->inexact
|
(exact->inexact
|
||||||
(+ 1 (modulo
|
(modulo
|
||||||
(+ (inexact->exact (pseudo-random-generator-x11 s))
|
(u32+ (inexact->exact (pseudo-random-generator-x11 s))
|
||||||
z)
|
z)
|
||||||
Im1))))))]
|
Im1)))))]
|
||||||
[x (random-n! x
|
[x (random-n! x
|
||||||
Im1
|
Im1
|
||||||
(lambda (z)
|
(lambda (z)
|
||||||
(pseudo-random-generator-x12-set!
|
(pseudo-random-generator-x12-set!
|
||||||
s
|
s
|
||||||
(exact->inexact
|
(exact->inexact
|
||||||
(+ 1 (modulo
|
(modulo
|
||||||
(+ (inexact->exact (pseudo-random-generator-x12 s))
|
(u32+ (inexact->exact (pseudo-random-generator-x12 s))
|
||||||
z)
|
z)
|
||||||
Im1))))))]
|
Im1)))))]
|
||||||
[x (random-n! x
|
[x (random-n! x
|
||||||
(- Im2 1)
|
(- Im2 1)
|
||||||
(lambda (z)
|
(lambda (z)
|
||||||
|
@ -127,7 +129,7 @@
|
||||||
s
|
s
|
||||||
(exact->inexact
|
(exact->inexact
|
||||||
(+ 1 (modulo
|
(+ 1 (modulo
|
||||||
(+ (inexact->exact (pseudo-random-generator-x20 s))
|
(u32+ (inexact->exact (pseudo-random-generator-x20 s))
|
||||||
z)
|
z)
|
||||||
(- Im2 1)))))))]
|
(- Im2 1)))))))]
|
||||||
[x (random-n! x
|
[x (random-n! x
|
||||||
|
@ -136,20 +138,20 @@
|
||||||
(pseudo-random-generator-x21-set!
|
(pseudo-random-generator-x21-set!
|
||||||
s
|
s
|
||||||
(exact->inexact
|
(exact->inexact
|
||||||
(+ 1 (modulo
|
(modulo
|
||||||
(+ (inexact->exact (pseudo-random-generator-x21 s))
|
(u32+ (inexact->exact (pseudo-random-generator-x21 s))
|
||||||
z)
|
z)
|
||||||
Im2))))))]
|
Im2)))))]
|
||||||
[x (random-n! x
|
[x (random-n! x
|
||||||
Im2
|
Im2
|
||||||
(lambda (z)
|
(lambda (z)
|
||||||
(pseudo-random-generator-x22-set!
|
(pseudo-random-generator-x22-set!
|
||||||
s
|
s
|
||||||
(exact->inexact
|
(exact->inexact
|
||||||
(+ 1 (modulo
|
(modulo
|
||||||
(+ (inexact->exact (pseudo-random-generator-x22 s))
|
(u32+ (inexact->exact (pseudo-random-generator-x22 s))
|
||||||
z)
|
z)
|
||||||
Im2))))))])
|
Im2)))))])
|
||||||
(void)))
|
(void)))
|
||||||
|
|
||||||
(define (random-n! x Im k)
|
(define (random-n! x Im k)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user