How can I use randomSeed to produce multiple variations of an array while using all elements of array ONLY once?
in
Programming Questions
•
11 months ago
Hi,
I am reading in information from a file into an arrayList. This list consists of strings. I am having one of those "when I see the solution I'll feel really stupid" moments. I know how to use random() and I know how to use randomSeed(). For example:
But this doesn't ensure that each string in words [ ] is used once and only once (ie: some strings are used more than once while some aren't represented at all). I am looking for a way to randomize my array based on different seeds, while ensuring that each new permutation includes all the elements from the original array and only uses them once.String[] words = {"apple", "bear", "cat", "dog", "yak", "pear", "bat", "antelop"};int index = words.length;
randomSeed(2);for (int i=0; i < index; i++) {int r = (int) random (index);println (words[r]);}
Any suggestions would be greatly appreciated.
Thanks,
JW
1