I'm working on creating a range of numbers between 1 and 2 using the imported math.random() class.
Here's how I got it working so far, however I can't see how it would work:
int tmp = (int)(Math.random()*1)+1;
Anyonould?e know if that actually works to get the range? if not.. then what
EDIT: Looking for either the number 1 or 2.
If you want the values 1 or 2 with equal probability, then int temp = (Math.random() <= 0.5) ? 1 : 2;
is all you need. That gives you a 1 or a 2, each with probability 1/2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With