Advertisement

graph of distribution of dice rolls

Started by February 20, 2002 02:57 PM
12 comments, last by krez 22 years, 11 months ago
my old book and my calculator had an nPr function, and an nCr function, I forget the actual formula for them a long time ago but I think that is what you want. It seems to be a lost formula now that I search for it.
quote:
Original post by krez
all i really want is a few nice graphs to compare when i''m deciding if some stat should be 3d6 or 6d3.

The lower bound of the score is the first number.
The upper bound of the score is the first number multiplied by the second.
The mean and median averages will be the second number + 1, divided by 2. If the first number is greater than 1, this will also be the modal average.

3d6: min = 3, average = 10.5, max = 18
6d3: min = 6, average = 12, max = 18

Increasing the first number also decreases the variance of the data. This means that you''re less likely to get extreme values. This is because there are more combinations that can achieve the central values than the extreme values. (Example: 2d6... there is only one way to score 2, with a 1 on each die, but there are 6 different ways to score 7... 1+6, 2+5, 3+4, 4+3, 5+2, and 6+1). So increasing the number of dice makes the roll more predictable.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
Advertisement
Well, I''m a little lost by the derivation from the multinomial and if you don''t know the notation then the equation itself can be a bit daunting, but it is fairly simple to implement:

  // calc n!/(k!*(n-k)!), i.e. nCr(n,k)int combin(int n, int k){   int i, l, num = n, den = 1;   l = (k > (n - k)) ? (n - k) : k;   if (l == 0)   {      num = 1;      den = 1;   }   else   {      for (i = 2; i <= l; i++)      {         num *= n-i+1;         den *= i;      }   }   return(num/den);}//calc prob of getting total p from n s-sided dicefloat prob(int p, int n, int s){   int i;   int iSign = -1;   int count = combin(p - 1, n - 1);   if ((p < n) || (p > pow(s,n)))      count = 0;   else   {      for (i = 1; i <= (p - n) / s; i++)      {         count += sign*combin(n,k)*combin(p - s*i - 1, n - 1)         sign *= -1;      }   }   return(((float) count)/pow(s,n));}  


As before there might be a few errors.
Keys to success: Ability, ambition and opportunity.
One apology first. In my last post, I made a reference to the hyper-geometric distribution. I was thinking of the wrong combinatoric equation... sorry. The equation I meant was for combinations with repetitions, which is similar to sampling with replacement, but subtely different. One can be derived from the other, but it is not so obvious.

quote:
Original post by LilBudyWizer
You lost me there. You don''t need to know how many ways to get x1 A1''s and so forth. The multinomial calculates the probability of getting any of them. Getting the xn''s is from my view the challenge. Now perhaps combinatoric provides a method for finding the xn''s, but you don''t say that.



Unfortunately, I left out the words that if we know how many different ways you could obtain Ai then you would know the value of xi. I assumed that was obvious. My apologies.

quote:
Original post by LilBudyWizer
Here is a link that explains how to calculate the probability of a given total.



Yes, the above hyperlink to Mathworld shows one method of combining the multinomial distribution with the combinatoric equation for combinations with repetitions , which is the solution path I was suggesting (albeit with an incorrect mathematical reference).

Ultimately, you don''t need graphs krez. What you really need are the first two moments of the distribution so that you can know what the most likely outcome of rolling the dice will be (the maximum likelihood outcome will be the same as the distribution mean since the distribution is symmetric and uni-modal) and an estimate of how widely the die rolls with be distributed about this value (the second moment of the distribution: it''s covariance). These can be computed fairly trivially from a Monte Carlo simulation.

Good luck in what ever you choose to do,

Timkin

This topic is closed to new replies.

Advertisement