How to shuffle the elements in the pairs?
The program below, generate all possible pairs and later shuffle the pairs.
e.g. possible pairs before shuffle is ab,ac,ae,af
..etc shuffled to ac,ae,af,ab
...etc
How to make it not only shuffled in pairs but within the elements in the pair itself?
e.g. instead of ab, ac,
how can I make ba, ac
?
String[] pictureFile = {"a.jpg","b.jpg","c.jpg","d.jpg","e.jpg","f.jpg","g.jpg"};
List <String> pic1= Arrays.asList(pictureFile);
...
ListGenerator pic2= new ListGenerator(pic1);
ArrayList<ArrayList<Integer>> pic2= new ArrayList<ArrayList<Integer>>();
public class ListGenerator {
public ListGenerator(List<String> pic1) {
int size = pic1.size();
// create a list of all possible combinations
for(int i = 0 ; i < size ; i++) {
for(int j = (i+1) ; j < size ; j++) {
ArrayList<Integer> temp = new ArrayList<Integer>();
temp.add(i);
temp.add(j);
pic2.add(temp);
}
}
Collections.shuffle(pic2);
}
//This method return the shuffled list
public ArrayList<ArrayList<Integer>> getList() {
return pic2;
}
}