美文网首页
iOS随机数

iOS随机数

作者: 暗夜行者K | 来源:发表于2022-06-13 16:47 被阅读0次

常用方法:arc4random

1、获取一个随机整数范围在:[0,100)包括0,不包括100

int x = arc4random() % 100;

2、  获取一个随机数范围在:[500,1000),包括500,不包括1000

int y = (arc4random() % 501) + 500;

3、获取一个随机整数,范围在[from,to),包括from,不包括to

-(int)getRandomNumber:(int)from to:(int)to

{

    return (int)(from + (arc4random() % (to – from + 1)));

}

相关文章

网友评论

      本文标题:iOS随机数

      本文链接:https://www.haomeiwen.com/subject/qbiomrtx.html