mardi 4 août 2015

ArrayList shuffled String Array recall

I've used an ArrayList to store a number of Strings so that they can be shuffled to select from at random (random being I call the first value/array and it is an unknown array, having been shuffled). I want to then use this newly randomly selected array to choose a value from within it and assign that to a variable.

    `ArrayList die = new ArrayList();
    String[] D1 = {"A","B","B","J","O","O"};
    die.add(D1);
    String[] D2 = {"G","N","W","E","H","E"};
    die.add(D2);
    String[] D3 = {"E","E","N","U","I","S"};
    die.add(D3);
    String[] D4 = {"I","T","Y","D","T","S"};
    die.add(D4);
    String[] D5 = {"S","E","O","T","I","S"};
    die.add(D5);
    String[] D6 = {"R","D","I","X","L","E"};
    die.add(D6);
    String[] D7 = {"N","N","Z","R","H","L"};
    die.add(D7);
    String[] D8 = {"O","T","W","A","T","O"};
    die.add(D8);
    String[] D9 = {"E","E","G","A","N","A"};
    die.add(D9);
    String[] D10 = {"R","E","T","T","Y","L"};
    die.add(D10);
    String[] D11 = {"S","P","C","A","H","O"};
    die.add(D11);
    String[] D12 = {"O","U","M","C","I","T"};
    die.add(D12);
    String[] D13 = {"E","T","W","R","H","V"};
    die.add(D13);
    String[] D14 = {"Qu","N","M","I","U","H"};
    die.add(D14);
    String[] D15 = {"F","F","P","S","A","K"};
    die.add(D15);
    String[] D16 = {"D","R","Y","V","E","L"};
    die.add(D16);
    Collections.shuffle(Arrays.asList(die));`

I've tried using the String diceOne = die.get(new Random().toString(die.get(0).Length)); function to recall a String value from the first shuffled array at random, but it isn't working. Any ideas?




Aucun commentaire:

Enregistrer un commentaire