随机数的生成以及排序 iphone
随机数的生成:
for (int i = 0; i<100; i++) {
unsigned int randomNumber =
arc4random() %100;
NSLog(@"randomNumber:%d",randomNumber);
}
排序:
NSMutableArray *randomArray = [NSMutableArray arrayWithObjects:
[NSNumber numberWithInt:12],
[NSNumber numberWithInt:8],
[NSNumber numberWithInt:15],
[NSNumber numberWithInt:1],
[NSNumber numberWithInt:60],
nil];
[randomArray sortUsingComparator:
^NSComparisonResult(id obj1, id obj2) {
NSNumber *number1 = (NSNumber *)obj1;
NSNumber *number2 = (NSNumber *)obj2;
return [number1 compare:number2];
}];
NSLog(@"randomArray:%@",randomArray);