vendredi 15 décembre 2017

Java - Generating random number in a range between two previous random numbers

in my main method I have two methods. The first method generates a number between 1 and 100. The second method generate a number between 1 and number generated from first method.

The third method should generate a random number between number from method1, and number from method2. I have tried this, but it doesn't work correctly.

public int randomThree() {

    random3 = rand.nextInt(random1 + random2) + 1;

    return random3;
}

Also, if I wanted to create a method that returns an array of 15 random numbers without duplicates, how would I do that?

Thanks




Aucun commentaire:

Enregistrer un commentaire