Skip to content

Instantly share code, notes, and snippets.

@baxiang
Created April 13, 2015 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baxiang/abf5d7c249c3506a8c9b to your computer and use it in GitHub Desktop.
Save baxiang/abf5d7c249c3506a8c9b to your computer and use it in GitHub Desktop.
获取一个随机数
:arc4random() 常用方法集合
//获取一个随机整数范围在:[0,100)包括0,不包括100
int x = arc4random() % 100;
//获取一个随机数范围在:[500,1000),包括500,不包括1000
int y = (arc4random() % 501) + 500;
//获取一个随机整数,范围在[from,to),包括from,不包括to
-(int)getRandomNumber:(int)from to:(int)to
{
return (int)(from + (arc4random() % (to – from + 1)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment