I have two ArrayList<ArrayList<String>>'s thant are the same size. The following code checks to see if the corresponding ArrayLists have any elements that are equal. If they do, they are both shuffled and the program rechecks and repeats.
boolean b=true;
int counter=0;
while(b==true)
{
for(int i=0; i<arraylist1.size(); i++)
{
for(int j=0; j<arraylist2.size(); j++)
{
for(String s1: arraylist1.get(i))
{
for(String s2: arraylist2.get(j))
{
if(s1.equals(s2))
{
counter++;
}
}
}
}
}
if(counter==0)
{
b=false;
}
else
{
long random = System.nanoTime();
Collections.shuffle(arraylist1, new Random(random));
long random2 = System.nanoTime();
Collections.shuffle(arraylist2, new Random(random2));
counter=0;
}
}
What I know the problem is NOT: I know it is NOT the case that the two ArrayLists must have corresponding ArrayLists with the same element (i.e., there IS a shuffling of the ArrayLists such that all corresponding ArrayLists will have different elements). I also know it's not computational time.
What I think the problem may be: I think there is something inherently "unrandom" with the shuffling method I call, but honestly, I have no idea why this is not working. In fact, when I do this program with the code b=false at the end (to take me out of the loop no matter what and see how arraylist1 and arraylist2 compare) the ArrayLists are most of the time (correspondingly) different! Yet the program ALWAYS runs into an infinite loop despite this!