dimanche 25 septembre 2022

printout only one time array items

i made this little class that printout in rando my array, but sometimes catch 2 or more times the same index.

es: 2 cook 3 pick 4 relax 3 pick

how can i make it to print only 1 time any item shuffled ?

es: 2-1-3-4 ecc...

i need it to remain an array. thanks for help

here the code:

java.util.Random random = new java.util.Random();

String[] lista = {"1 drink","2 cook","3 pick","4 relax"};

public String[] getLista() {
    return lista;
}

public void setLista(String[] lista) {
    this.lista = lista;
}


public String randomNumber(String[] lista) {
    int rnd = new Random().nextInt( lista .length);
     return lista[rnd];



Aucun commentaire:

Enregistrer un commentaire