Possible Duplicate:
What’s the Best Way to Shuffle an NSMutableArray?
Here in my code I want to shuffle the elements in the array and try to print it out, but it's not shuffling properly, I tried what is shown here.Its working but,it values are repating.
for(UIView *view in self.view.subviews)
{
if([view isKindOfClass:[UIButton class]])
{
button= (UIButton *)view;
if (button.tag >=1 && button.tag <=20)
{
for (NSUInteger i = 0; i < count; ++i)
{
[texts rotate];
// Select a random element between i and end of array to swap with.
int nElements = count - i;
int n = (arc4random() % nElements) + i;
[texts exchangeObjectAtIndex:i withObjectAtIndex:n];
//int myTag= j+1;
//button = [self.view viewWithTag:myTag];
name=[NSString stringWithFormat:@"%@",[texts objectAtIndex:n]];
[button setTitle:name forState:UIControlStateNormal];
NSLog(@"current name :%@",name);
}
}
}
}
After shuffling the array values are repeating,pls help me to solve this issue