ios 数组打乱顺序

-(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;

猜你喜欢

转载自www.cnblogs.com/tufei7/p/9888524.html