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

Was it helpful?

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
scroll top