; Returns a generator of streams of random normal deviates. ; http://cap-lore.com/code/Scheme/grnd.txt (let ((v (fileVal "RC4"))(sc (/ 1. (expt 2 55)))) (lambda (S) (let* ((f #f)(v (ex 'nv (v 'nb S)))(m 0)(gf (lambda () (- (* (v 7) sc) 1)))) (write (list 'Boo sc))(newline) (lambda () (if f (begin (set! f #f) m) (let xx () (let* ((x (gf))(y (ex 'gfr (gf)))(s (ex 'd2 (+ (* x x)(* y y))))) (if (> s 1.) (xx) (let ((r (sqrt (/ (* -2 (log s)) s))))(set! m (* x r)) (set! f #t) (* y r)))))))))) ; tests (define g1 ((fileVal "RND") "foos")) (let r ((n 10000)) (if (zero? n) 0 (+ (g1) (r (- n 1))))) ; => -142.48347 (let r ((n 10000)) (if (zero? n) 0 (let ((w (g1))) (+ (* w w) (r (- n 1)))))) ; => 9651.553873202625 (let r ((n 10000)) (if (zero? n) 0 (+ (* (g1) (g1)) (r (- n 1))))) (let r ((n 10000) (s 0)) (if (= n 0) s (r (- n 1) (+ s (g1)))))