Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

random BOOLs in an efficient way for cocos2d

According to Steffen's post this is an efficient way to generate random BOOLs in cocos2d

+(BOOL) getYesOrNo
{
   return (CCRANDOM_0_1() < 0.5f);
}

but how do I set a range for this? (e.g. 0 - 29 is the interval and 5 ones BOOL = NO, 25 ones BOOL = YES )

like image 851
el.severo Avatar asked Feb 06 '12 10:02

el.severo


1 Answers

you can do something like this:

+(BOOL) getYesOrNo
{
    int tmp = (arc4random() % 30)+1;
    if(tmp % 5 == 0)
        return YES;
    return NO;
}
like image 72
nicoz_88 Avatar answered Sep 21 '22 17:09

nicoz_88