mercredi 16 décembre 2020

java random number bound by a variable

I've got two Integer variables that are generated randomly

int scoreWon = random1.nextInt(20);
int scoreLost = random1.nextInt();

What I want to do is , bound the scoreLost value by scoreWon so the generated number will always be less than the value generated by scoreWon.

Is this way possible ?

int scoreWon = random1.nextInt(20);
int scoreLost = random1.nextInt(scoreWon);

or please help me out




Aucun commentaire:

Enregistrer un commentaire