Feb 21, 2008

How to generate a random number in Scheme.

I couldn't find a function that generates a random number.
Instead, I make that function using "".

I wont to get current time for a seed.
But I couldn't a function for it.


(define (rand seed)
(let ((x seed))
(lambda ()
(set! x (remainder (+ (* 13 x) 5) 24))
x)))



(define a (rand 1))

(display (a))
(newline)
(display (a))
(newline)
(display (a))
(newline)



18
23
16

No comments: