percent chance~better way?
Posted: Tue Jul 21, 2009 5:55 pm
i know how to do rand(5) if(rand== 1){yea} but is there a better way to do percent chance then the way i came up with?
then where ever your action is
i guess this works, but it isn't really 25% it's kinda if the number is less then the number you picked out of a random number ranged from 0 - 100.....there has to be a better way to do this, or should i just go back to the good 'ol fashioned way?
- Code: Select all
void chance(int percent)
{
i = round(rand(100));
if(i <= percent)
{
p = i;
}
}
then where ever your action is
- Code: Select all
chance(25);
if(i == P)
{
//do stuff
}
i guess this works, but it isn't really 25% it's kinda if the number is less then the number you picked out of a random number ranged from 0 - 100.....there has to be a better way to do this, or should i just go back to the good 'ol fashioned way?