Hello,
I am trying to take a number, like 46 for instance, and adjust it based on it's probability.
My function:
int adjust_chance(int chance, int max) {
return (int)( chance < rand()%max; ? chance+1 : chance-1 )
}
Currently the call adjust_chance(46,100) would return 45, more often than it would return 46.
But what I want to do is adjust it so that after 3 adjustments, it would become 0 or 100.
math/probability expert needed!
Started by askiba, Mar 17 2009 02:29 AM
2 replies to this topic
#1
Posted 17 March 2009 - 02:29 AM
|
|
|
#2
Posted 17 March 2009 - 08:18 AM
Huh? First of all, adjust_chance(46,100) should return 45 or 47. Second, you can't guarantee going to 0 or 100 after three calls unless you want to guarantee it goes to 0 or 100 after one call.
#3
Posted 17 March 2009 - 08:46 AM
askiba said:
Hello,
I am trying to take a number, like 46 for instance, and adjust it based on it's probability.
My function:
int adjust_chance(int chance, int max) {
return (int)( chance < rand()%max; ? chance+1 : chance-1 )
}
Currently the call adjust_chance(46,100) would return 45, more often than it would return 46.
I am trying to take a number, like 46 for instance, and adjust it based on it's probability.
My function:
int adjust_chance(int chance, int max) {
return (int)( chance < rand()%max; ? chance+1 : chance-1 )
}
Currently the call adjust_chance(46,100) would return 45, more often than it would return 46.
double chance( double odds )
{
assert( 0.00 <= odds && 100.00 >= odds );
double result;
result = 0.00;
result = static_cast< double >( ::rand() % 100 ); // get pseudo random value 0-100
result = (( result / 100 ) * ( odds / 100 )) * 100; // use multiplication rule for 2 independent events P( A & B ) = P( A ).P( B )
return result;
}
askiba said:
But what I want to do is adjust it so that after 3 adjustments, it would become 0 or 100.
1. it can, and probably will, take more than 3 calls and
2. chance is never incremented because highest multiplier will be 1.
Hope this helps. (:


Sign In
Create Account

Back to top









