在开发程序中,需要每次随机出现一组数据的顺序下面是随机数算法
NSArray *temp = [NSArrayarrayWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", nil];
NSMutableArray *tempArray = [[NSMutableArrayalloc] initWithArray:temp];
NSMutableArray *resultArray = [[NSMutableArrayalloc] init];
int i;
int count = temp.count;
for (i = 0; i < count; i ++) {
int index = arc4random() % (count - i);
[resultArray addObject:[tempArray objectAtIndex:index]];
[tempArray removeObjectAtIndex:index];
}
[tempArray release];
NSLog(@"resultArray is %@",resultArray);
NSLog(@"看看结果楼");