Question

I would like my IBAction to randomly pick one of the actions in the brackets.

How do I do this?

Thanks!

- (IBAction) randomAction{

[self choice1];
[self choice2];
[self choice3];

}
Was it helpful?

Solution

Try this

- (IBAction) randomAction{
    switch (arc4random()%3){
        case 0:
                [self choice1];
            break;
        case 1:
            [self choice2];
            break;
        case 2:
            [self choice3];
            break;
        default:
            break;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top