- (NSArray*)shuffleArray:(NSArray*)array {
NSMutableArray *temp = [[NSMutableArray alloc] initWithArray:array];
for(NSUInteger i = [array count]; i > 1; i--) {
NSUInteger j = arc4random_uniform(i);
[temp exchangeObjectAtIndex:i-1 withObjectAtIndex:j];
}
return [NSArray arrayWithArray:temp];
}
Reference
No comments:
Post a Comment