I know how to generate numbers with Rails but I don’t know how to generate negative numbers?
prng.rand(1..6) for random of [1, 2, 3, 4, 5, 6]
Random doc says that you would get an ArgumentError.
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.
Let’s say you want to generate a number between a and b you can always do that using this formula:
So if you want a number between -8 and +7 for example then a=-8 and b=7 and your code would be
which is equivalent to