In scheme I have to use random to define a procedure that accepts no arguments and returns an integer in the range 1 to 10, inclusive and i cant use if. im lost =(
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
If your Scheme provides a random
function, you want 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]
Be advised that this isn't standards-compliant. For absolute portability, write your own RNG.