开发者

Randomly pick between 2 defined ints

开发者 https://www.devze.com 2023-02-28 08:04 出处:网络
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:

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

精彩评论

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