samedi 24 mars 2018

Single Java Random number trying to get the fixed range

I'm trying to generate a random number generator that has a fixed 1-100 range being int min = 1 and int max = 100. I managed to get this code so far. Using BlueJ as the environment.

import java.util.Random; 

public class RandomNumber { 
    public static int getRandomNumberInts(int min, int max) { 
        Random random = new Random(); 
        return random.ints(min,(max+1)).findFirst().getAsInt(); 
    }
} 

Is there any other way I can get a fixed number within my range without the need to enter the range myself?




Aucun commentaire:

Enregistrer un commentaire