码迷,mamicode.com
首页 > 移动开发 > 详细

ios 数组打乱顺序

时间:2018-11-01 12:33:14      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:span   mutable   array   ret   count   while   oid   from   turn   

-(NSMutableArray*)getRandomArrFrome:(NSArray*)arr
{
    NSMutableArray *newArr = [NSMutableArray new];
    while (newArr.count != arr.count) {
        //生成随机数
        int x =arc4random() % arr.count;
        id obj = arr[x];
        if (![newArr containsObject:obj]) {
            [newArr addObject:obj];
        }
    }
    return newArr;
}

 

NSArray+YYAdd 这个shuffle方法不知道行不行

/**
 Sort the object in this array randomly.
 */
- (void)shuffle;

ios 数组打乱顺序

标签:span   mutable   array   ret   count   while   oid   from   turn   

原文地址:https://www.cnblogs.com/tufei7/p/9888524.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!