Complete exercise 3.6

This commit is contained in:
Oliver Payne 2022-04-21 21:18:22 +01:00
parent 079ee8d08e
commit ab4554fcd8
1 changed files with 10 additions and 3 deletions

13
3_5.rkt
View File

@ -7,11 +7,18 @@
(modulo (+ (* a x) b) m)))
(define random-init 7) ;**not in book**
(define rand
(let ((x random-init))
(lambda ()
(set! x (rand-update x))
x)))
(lambda (arg)
(cond ((eq? arg 'reset)
(lambda (seed)
(set! random-init seed)))
((eq? arg 'generate)
(set! x (rand-update x))
x)
(else
(error "rand - unknown argument" arg))))))
(define (random-in-range low high)
(let ((range (- high low)))