#### Archived

This topic is now archived and is closed to further replies.

# graph of distribution of dice rolls

This topic is 5989 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i am trying to work out the number and sides of dice to use in my RPG for different things, but i want to see the distributions of the rolls so i don''t have to trial-and-error it [as much]... right now i have a little program i wrote, which takes the number of dice and how many sides they have for input, and "rolls" them a bunch of times and draws a distribution graph of it for me. however, this is slow and innaccurate unless i use a huge number of iterations (i use 10000 usually, and even then the graph isn''t as smooth and symmetrical as it should be). is there a formula for this? so i could draw the graphs as they "should be"? thanks in advance. --- krez (krezisback@aol.com)

##### Share on other sites
Maybe the binomial distribution can be used for what you're trying to graph.

Edited by - grady on February 20, 2002 5:51:02 PM

##### Share on other sites
with my google search i found out that that won't work (here), as well as a bunch of pages telling me how to use various dice-rolling software for various statistics classes around the world...
thanks for the attempt though!

EDIT -- wow, i left a quote out of the link and the forum got real thin...

Edited by - krez on February 20, 2002 6:34:42 PM

##### Share on other sites
Krez, you seek the multinomial distribution, since the outcome of rolling n dice is the same outcome as rolling 1 die n times and each roll is mutually exclusive.

Cheers,

Timkin

##### Share on other sites
You can use brute force:

  int Count(int iDice, int iSides, int *piCount){ int iDie[iDice]; int i, iSum; char bDone = 0; for (i = 0; i < iDice; i++) iDie[i] = 1; for (i = 0; i < iDice * iSides; i++) piCount[i] = 0; while (!bDone) { int iSum = 0; for (int i = 0; i < iDice; i++) iSum += iDie[i]; piCount[iSum]++; for (i=0, iDie[0]++; (i < (iDice - 1) && (iDie[i] > iSides); i++) { iDie[i] = 1; iDie[i+1]++; } if (i == (iDice - 1)) bDone = 1; } return(pow(iSides, iDice));}

There might be a few errors, but it at least gives the general idea. The return value is the total number of possible outcomes. It is the same value you would get from summing the piCount array. The probability of a number, i, occuring is piCount/iTotal where iTotal is the value returned by the function. The only reason for actually using a generator is to verify that the numbers generated are actually distributed as they should be.

I assume there are less computationally intensive methods to find the probability of a given sum, but right now I''m at a loss as to what that might be. Since it is semetric you can cut it in half by stopping when the last digit passes the halfway mark. So with a 3d6 you could stop when the 3rd die rolls over to 4.

##### Share on other sites
quote:
Original post by LilBudyWizer
You can use brute force:

...which is exactly what krez is doing LBW! From his original post it appears he is doing a Monte Carlo simulation rather than an ordered search, but either way, it's brutish and forceful and has none of the elegance of solving for the distribution analytically!

quote:
Original post by LilBudyWizer
I assume there are less computationally intensive methods to find the probability of a given sum, but right now I'm at a loss as to what that might be.

As I said, it's the multi-nomial distribution. If you flip a coin many times and want to know the probability distribution over numbers of heads and tail, it's the binomial distribution. For a sampling procedure with exactly k mutually exclusive outcomes (A1,...,Ak), with probabilities p1, ,..., pk respectively, it can be shown that the probability of getting x1 outcomes of type A1, x2 of A2,..., xk of Ak, is given by the multinomial distribution:

f(x1,...,xk) =          n!                  ------------ p1x_1...pkx_k                    x1!...xk!

where p1 + ... + pk = 1 and there are n trials (i.e., you roll n dice). So long as you are careful to renormalise your probabilities of each outcome, you can use dice of differing side numbers in this computation.

Good luck,

Timkin

Edited by - Timkin on February 21, 2002 8:26:51 PM

##### Share on other sites
Well, it seems it would be a bit challenging for him to figure out exactly how he is going to use that to find the probabilities of a given total. It isn''t quite as straight forward as you make it sound since you have to find all the sequences and then calculate the probability of each sequence. With a 10D10 that is at least just around 10^5 instead of 10^10. It is still pretty much a brute force approach since you with a 10D10 there are only 91 totals, but around 10^5 sequences.

I don''t feel up to showing the actual code, but you would generate the sequences by generating all sequences where each number is less than or equal to all the numbers before it. Once you have a given sequence you have to count how many times a given value occurs, i.e. how many dice came up one. Then you plug those counts in for the x''s in the multinomial probability density function. Assuming all your dice have the same number of sides then all the p''s are equal to 1/sides. You have to sum all the dice to figure out what you are calculating the probability of and sum all the probabilities for all the sequences that sum to the same value.

If you do it correctly then when you are done if you sum all the probabilities for all the totals it should equal one. You most likely will not be exactly equal to one due to the number of computations. You should be very close to it though.

##### Share on other sites
... that would be true, if there weren''t this wonderful little field within mathematics called Combinatorics! Using Combinatorics we can determine analytically how many ways there are of getting x1 A1''s, x2 A2''s, ... , xk Ak''s and from this we have the sequences you mentioned.

I''m not going to post the entire solution method here, because then noone would learn anything. You learn by doing.

I will give a hint though... consider the hyper-geometric distribution!

Good luck,

Timkin

##### Share on other sites
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.

Here is a link that explains how to calculate the probability of a given total. The P(p,n,s) function is a function taking the total of interest, p, the number of dice, n, and the number of sides, s.

Edited by - LilBudyWizer on February 22, 2002 10:14:02 AM

##### Share on other sites
ha ha ha.
thanks yous guys, i really do appreciate it... but apparently i''m not as good at mathematics as i once was (or thought i was?)...
and this is not to say that i am uninterested in learning... but really, to even come close to getting this i''d have to reread a few (several?) of those books i still have from school, and all i really want is a few nice graphs to compare when i''m deciding if some stat should be 3d6 or 6d3.
perhaps some day i will want to become learned in these things, but i do know enough probability to say it isn''t likely
brute force it is i guess... dammit...

--- krez (krezisback@aol.com)

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 14
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631757
• Total Posts
3002131
×