Schematic: Creating a Random Range

In the scheme, I should use random to define a procedure that takes no arguments and returns an integer in the range from 1 to 10 inclusive, and I cannot use if. im lost = (

0
source share
1 answer

If your circuit provides a function random, you want to either

(define (1-10-rand)
    (+ 1 (random 10)))

or

(define (1-10-rand)
    (floor (* 10 (random))))

depending on whether you have (random n) --> integer in [0, n-1])or(random) -> float in [0,1]

Please note that this is not up to standard. For ultimate mobility, write your own RNG.

+4
source