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?
精彩评论