Get random numbers in a specific range in java

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

Possible Duplicate:
http://stackoverflow.com/questions/363681/java-generating-random-number-in-a-range http://stackoverflow.com/questions/363681/java-generating-random-number-in-a-range


I want to generate random numbers using

java.util.Random(arg);

The only problem is, the method can only take one argument, so the number is always between 0 and my argument. Is there a way to generate random numbers between (say) 200 and 500?

Answers

Random rand = new Random(seed);
int random_integer = rand.nextInt(upperbound-lowerbound) + lowerbound;

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/11743267/get-random-numbers-in-a-specific-range-in-java

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils