Skip to content

Instantly share code, notes, and snippets.

@ta1kt0me
Created May 6, 2014 09:03
Show Gist options
  • Save ta1kt0me/a2ea2763d6c1f0d55b0a to your computer and use it in GitHub Desktop.
Save ta1kt0me/a2ea2763d6c1f0d55b0a to your computer and use it in GitHub Desktop.
-(NSMutableArray *)createNSMutableArray:(int)max
{
NSMutableArray *numberArray = [NSMutableArray new];
for (int i=1; i<=max; i++) {
[numberArray addObject:[NSNumber numberWithInt:i]];
}
[self sortByRandom:numberArray];
return numberArray;
}
-(NSMutableArray *)sortByRandom:(NSMutableArray *)array
{
int arraySize = [array count];
while (--arraySize >= 0) {
int rand =arc4random()%totalCount;
[array exchangeObjectAtIndex:rand withObjectAtIndex:arraySize];
}
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment