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

}

相关文章:

  • 2021-11-30
  • 2021-11-04
猜你喜欢
  • 2021-11-30
  • 2022-12-23
  • 2021-10-15
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
相关资源
相似解决方案