vendredi 3 mai 2019

Random numbers without duplicates in java

i do like it :

    int randOne = 3;
    int randTwo = 4;
    int oneNubmer;
    int twoNumber;

    do {
         oneNubmer = 1 + (int) (Math.random() * randOne);
         twoNumber = 1 + (int) (Math.random() * randTwo);
    } while (oneNubmer == twoNumber);

It works, but increases operation time greatly, because this function is called 1000+ times.

How to do it better?




Aucun commentaire:

Enregistrer un commentaire