This question already has an answer here:
How to Get Random Number Between Given Range in Java if minimum is more than 1? for example if i want to get random number between 6 to 20. currently i am using this code
Random rand = new Random();
int rnd = rand.nextInt(499) + 1;
it is working well, but if i change 1 to some high number for example 6, it will not work properly, i want to get random number that is between 6 and 20. is it possible using above function ?
Aucun commentaire:
Enregistrer un commentaire