How can generate a random number between 40 and 47 using ruby?
I tried that but could not understand. How do I generate a random number in a certain range with Ruby?
How can generate a random number between 40 and 47 using ruby? I tried
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.
rand(8)will generate a random number between 0 and 7 (note that there are indeed 8 numbers in that range).All you want to do is add 40 to that range, so you’ll get numbers between 40 and 47. Like this:
40 + rand(8)