首页 > 其他 > 详细

随机排列

时间:2015-02-03 16:42:33      阅读:244      评论:0      收藏:0      [点我收藏+]

// .h

#import <Foundation/Foundation.h>

 

@interface NSMutableArray (VIMI)

- (void)shuffle;

@end

 

 

 

#import "NSMutableArray+VIMI.h"

 

@implementation NSMutableArray (VIMI)

- (void)shuffle

{

    NSUInteger count = [self count];

    for (uint i = 0; i < count; ++i)

    {

        // Select a random element between i and end of array to swap with.

        NSInteger nElements = count - i;

        NSInteger n = arc4random_uniform(nElements) + i;

        [self exchangeObjectAtIndex:i withObjectAtIndex:n];

    }

}

@end

 

随机排列

原文:http://www.cnblogs.com/zhujin/p/4269968.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!