How do I generate random in Scheme? Is there a special form or would I have to create a procedure? And if so, how do I do that? (I’m trying to create a procedure called random-choice that inputs two strategies and returns one at random.)
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The procedure is called, surprisingly enough,
random– although the exact syntax might be different depending on the Scheme interpreter in use (read the documentation!), but the general idea is as follows:For returning one of two possible values, this will do the trick in Racket:
Notice that the
2argument passed torandomforces it to randomly return one of two possible values:0or1. So if(random 2)evaluates to0thenais returned, otherwisebis returned.