OC实现将N个数随机排列

 1 + (NSMutableArray *)randArray : (NSMutableArray *)arrayM

 2 {

 3 

 4     NSMutableArray *resultM = [[NSMutableArray alloc] initWithCapacity:arrayM.count];

 5     NSInteger count = arrayM.count;

 6     for (NSInteger i = 0; i < count; i ++)

 7     {

 8         NSInteger index = arc4random_uniform((unsigned int)arrayM.count);

 9         [resultM addObject:[arrayM objectAtIndex:index]];

10         [arrayM removeObjectAtIndex:index];

11         

12     }

13     return resultM;

14 }

 

你可能感兴趣的:(实现)