so i have a large amount of strings in a string array but for this case lets just say this:
String s =
"abc," +
"bac," +
"cba," +
"cab," +
"bca,";
//split s of all characters behind a comma and place them in a array
String[] sArray = s.split(",");
//assign a number to each index in sArray and assign a random index to desiredString
Random stringSelector = new Random();
int range = stringSelector.nextInt(sArray.length);
desiredString = sArray[stringSelector];
//print
System.out.println(desiredString);
the real problem here is that there will be too many occurrences of a certain index if you place this program in a loop
cab
cab
abc
cab
bac
cab
bca
cab
and adding more values to s
doesnt help the case because i am really working with a array with 81 strings
i was wondering if there is a way to shuffle every value in sArray
before having a number assigned to each index
or basically just creating a more "random" sequence than Random()
Aucun commentaire:
Enregistrer un commentaire