Search code examples
iosobjective-carc4random

Probability equation using arc4random ios


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];
    }