In my code, I spin a UIScrollView this way:
[carousel scrollByNumberOfItems:-35 duration:10.7550f];
[NSTimer scheduledTimerWithTimeInterval:10.7550f
target:self
selector:@selector(randomFinal)
userInfo:nil
repeats:NO];
And in this part, after the scrollView stops, it will do a random movement, either UP or Down:
-(void)randomFinal {
randomBut = arc4random()%5;
if (randomBut == 0){
[carousel scrollByNumberOfItems: -1 duration: 4.50f];
} else if ( randomBut == 1){
[carousel scrollByNumberOfItems: 1 duration: 4.50f];
} else if (randomBut == 2) {
[carousel scrollByNumberOfItems: 1 duration: 5.0f];
} else if (randomBut == 3) {
[carousel scrollByNumberOfItems: -1 duration: 5.0f];
} else if (randomBut == 4) {
[carousel scrollByNumberOfItems:0 duration:0];
}
}
What I need is to make the randomFinal part to happen with a percentage of 30% probability. How can I do it? thankyou.
You can try this:
The random number that results from the call to arc4random_uniform() should be <= 30, 30% of the time.