I would like to make random numbers in a specific range, like “pick a random number between 18 and 35”? How can I do that with the rand() function?
I would like to make random numbers in a specific range, like pick a
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.
If this is written in C, then you are pretty close. Compiling this code:
And running it in a pipeline produces this output:
The key is you forgot to add 1 — the fencepost error.
You can generalize this into a function: