Created
May 6, 2014 09:03
-
-
Save ta1kt0me/a2ea2763d6c1f0d55b0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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