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 }

 

posted @ 2014-05-16 20:04  撩课-Sz  阅读(246)  评论(0编辑  收藏  举报