开发者

Rolling dice application for iPhone apps

I am making an iPhone dice application and I wanted to create a button so that if I click it, it will generate a random number between 1 and 6 on the UITextField.

Can anyone help me out and give me a mathem开发者_开发问答atical formula to generate such number?

Thanks


If you are using Objective-C, try:

#include <stdlib.h>
int random_number = (arc4random() % 6) + 1;

The 6 is needed because arc4random() % n results on a number from 0 to n-1.


#include <stdlib.h>

int r = arc4random() % 6;

Results between 0 and 5. Adjust with a +1 for 1 to 6.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜