首页 > 技术文章 > 生成一定范围内的随机数

skyry 2015-10-22 10:26 原文

生成方法如下:

+(NSInteger)getRandomNumber:(NSInteger)from to:(NSInteger)to

{
    //eg:[1,10) 包含 1,不包含10;
    return (NSInteger)(from + (arc4random() % (to - from + 1)));

}

推荐阅读