开发者

Randomly pick between 2 defined ints

Is there a method in objective-c that allows you to pseudorando开发者_StackOverflow社区mly decide between two ints? Or is there a quick way to implement this?


Use the following:

int number = arc4random() % 2;
if(number==0){
  //pick one number
}else{
  //pick other number
}


randomSelection = arc4random() % 2 ? choice1 : choice2;


in C++ that would be result = rand() < 0.5 ? int1 : int2 why can't you build the same command in ObjC?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜