Probability equation using arc4random ios
-
23-12-2019 - |
Question
I want to perform a random action on a button click using probability. For example: If I click a button there is 6% chance of running A method and 94%chance of running B method
Solution
- (void)click
{
int chance = arc4random_uniform(100);
if (chance < 6)
[self runA];
else
[self runB];
}
OTHER TIPS
if(arc4random()%100 < 6){
//RunA
}
else{
//RunB
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow