I’m guessing this is very simple, but for some reason I am unable to figure it out. So, how do you pick a random integer out of two numbers. I want to randomly pick an integer out of 1 and 2.
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.
Just use the standard uniform random distribution, sample it, if it’s less than 0.5 choose one value, if it’s greater, choose the other:
Alternatively, you can use the
nextIntmethod which takes as input a cap (exclusive in the range) on the size and then offset to account for it returning 0 (the inclusive minimum):