[SOLVED] 代写 ;; code that provides random function

30 $

File Name: 代写_;;__code_that_provides_random_function.zip
File Size: 423.9 KB

SKU: 0613982150 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


;;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
30 $