I try to write a function that returns a random number between the first and the second argument.
(random-between 40 80)
Should give a random number between 40 and 80. Here is the code:
(define (random-between x y)
((set! result (random y))
(if (> result x)
result
(random-between x y))))
I suppose when the function runs recursively the second time, the random function creates a new result who is again tested and if it is above x it is output as the final result.
This is the first time I use "set!" and it gives me this error:
set!: unbound identifier in module in: result
The other similar questions didn't help me find a solution.
((set! result (random y)) ...)is nonsensical. Why not just uselet? - leppieset!will never do that. - leppie