jeudi 31 octobre 2019

How to i prevent duplicates when generating a random number

I want 7 different variables generating from 1-36 however the variables must not have the same number as before without using an array or arraylist within the shortest possible line

private final int getconsolationprice1=rand.nextInt(36);
private final int getconsolationprice2=rand.nextInt(36);
private final int getconsolationprice3=rand.nextInt(36);
private final int getconsolationprice4=rand.nextInt(36);
private final int getconsolationprice5=rand.nextInt(36);
private final int getconsolationprice6=rand.nextInt(36);
private final int gettopprice=rand.nextInt(36);



Aucun commentaire:

Enregistrer un commentaire