Jump to content

math/probability expert needed!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
askiba

askiba

    Newbie

  • Members
  • Pip
  • 3 posts
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.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
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.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
julmuri

julmuri

    Programmer

  • Members
  • PipPipPipPip
  • 139 posts

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.
If i remember right from school, heres how calculate propability of two independent events.

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.
Above function wont fill these requirements though because
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. (: