vendredi 28 octobre 2016

Generating a Random number from set array and returning it to main class

So I have an array of size 18, and I'm trying to generate a random number which represents the index location of one of the 18 numbers in the array and return that number from the array to the main method.

My code so far is this, and I've stuck for a while, so any help is appreciated.

public static int spinMethod() {
    int[] roll = new int[] {1000, 1500, 750, 600, 500, 100, 250, 750, 600, 1500, -1, 500, 1000, 1500, 750, -1, 500, 1500}; //creates array and assigns variables
    Random r = new Random(); //random number generator
    int x = 1 + r.nextInt(18);      
    return int[x];




Aucun commentaire:

Enregistrer un commentaire