[SOLVED] ;; code that provides random function

$25

File Name: ;;__code_that_provides_random_function.zip
File Size: 357.96 KB

5/5 - (1 vote)

;;code that provides random function

;ensure that random is defined at top level
(define (random) .5)

; initialize random, optionally with given seed between 1 and 2^31-1
; if no seed given, uses 1043618065
(define (init-random . user-seed)
(define (next-val seed)
(let* ((a 16807.0) ; 7^5
(m 2147483647.0) ; 2^31-1
(t (* a seed)))
(- t (* m (floor (/ t m))))))
(set! random
(let ((seed(if (null? user-seed) 1043618065 (car user-seed))))
(lambda()
(set! seed (next-val seed))
(/ seed 2147483647.0)))))

(init-random)

; after this, (random) will produce a pseudorandom number r, 0.0 < r < 1.0

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] ;; code that provides random function
$25