Google Answers Logo
View Question
 
Q: Multiple dice addition probabilities ( No Answer,   3 Comments )
Question  
Subject: Multiple dice addition probabilities
Category: Science > Math
Asked by: mnesin-ga
List Price: $10.00
Posted: 26 Feb 2004 09:39 PST
Expires: 27 Feb 2004 13:40 PST
Question ID: 311037
Background:
N standard dice are rolled. The points on all the dice are added
together, and that is the score. It is therefore possible to score a
low of N and a high of 6*N.

Question:
How can the probabilities of getting each potential score be calculated?

Requirements:
I currently have a recursive function to make the calculation. VERY
SLOW. I'm sure there is a much faster way. I would like a JavaScript
function that I pass N to, and it returns an N*6+1 length array of
numbers back, each from 0 to 1 inclusive and representing the odds of
getting the score of its index.

Template:
function CalcOdds(numDice)
{
   var odds=new Array(numDice*6+1);
   // Initialize all to 0
   for (var i=0;i<odds.length;i++)
      odds[i]=0;

   //Perform your magic

   return odds;
}

Examples:
numDice=0, odds=[1]
numDice=1, odds=[0,0.16667,0.16667,0.16667,0.16667,0.16667,0.16667]
numDice=2, odds=[0,0,0.02778,0.05556,0.08333,0.11111,0.13889,0.16667,0.13889,0.11111,0.08333,0.05556,0.02778]

Conclusion:
I'm hoping for fast here, like calculating for 20 die in less than a
second. I don't need a detailed explination, but if you had a quick
one great.

Thanks,
Scott
Answer  
There is no answer at this time.

Comments  
Subject: Re: Multiple dice addition probabilities
From: porteiro_head-ga on 26 Feb 2004 10:23 PST
 
I'll tell you how I would do it.  This will work with any similar
situation, not just dice.  I does however assume that you have an idea
what the maximum size you will ever use (e.g., maximum 1000 dice)

You say that you have a recursive function that will calculate N dice
for you.  If we assume that nMax == 1000, then run that function for
each integer from 1 to 1000.  Save the results, and then write a
function that has all of these results hard-coded into the function.

True, it's not mathematically elegant, but it will be super fast.  As
long as you can put a cap on the # of dice you will ever need, it
would work great.
Subject: Re: Multiple dice addition probabilities
From: mnesin-ga on 26 Feb 2004 14:44 PST
 
When I store the probabilities in a cache as I build them, and use the
cache from one set to build the next higher up, it's pretty quick. It
does 100 in about a second. Stack overflow at 1000 though. I was going
to stick with using the cache method if I don't get an answer, as I
doubt I'll need more than 200.

I'd cancel the question, but I'm still interested to see if there is a
non-recursive solution.
Subject: Re: Multiple dice addition probabilities
From: hailstorm-ga on 26 Feb 2004 17:39 PST
 
mnesin,

Here is a post on finding the probability of a sum on multiple dice:
http://mathforum.org/library/drmath/view/52207.html

This can be used to tell you the number of times a value will appear
if you have N number of 6-sided dice.  Then you can divide this number
by 6 raised to the power of N to get the probability of that number
coming up.

I'll leave it as an exercise to the questioner to figure out how to do
this in Javascript...

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy