0

So I'm using this function to make a random choice from a string array list

String[] names;
String random;

    Resources res = getResources();
    names = res.getStringArray(R.array.RandomList);

                        Random r = new Random();
                        int idx = r.nextInt(names.length);
                        random = (names[idx]);
                        mainText.setText(random);

but I want to know how to make sure that it won't choose the same item twice, does anyone know how to do that, thanks

  • lookup Fisher-Yates shuffle. In fact, I'm surprised you didn't notice all those answers down the right hand side.... Collections.Shuffle() – Mitch Wheat May 31 '15 at 00:00
  • This might help http://stackoverflow.com/questions/8115722/generating-unique-random-numbers-in-java – Mithun May 31 '15 at 00:00

0 Answers0