I am trying to calculate the distribution of the chances of changing the number of six-sided dice rolls. For example, 3d6 ranges from 3 to 18 as follows:
3:1, 4:3, 5:6, 6:10, 7:15, 8:21, 9:25, 10:27, 11:27, 12:25, 13:21, 14:15, 15:10, 16:6, 17:3, 18:1
I wrote this php program to calculate it:
function distributionCalc($numberDice,$sides=6) { for ( $i=0; $i<pow($sides,$numberDice); $i++) { $sum=0; for ($j=0; $j<$numberDice; $j++) { $sum+=(1+(floor($i/pow($sides,$j))) % $sides); } $distribution[$sum]++; } return $distribution; }
Inside the $ j for-loop, the magic of the floor and module functions is used to create a sequence of counting the base-6 with the number of digits being the number of dice, so 3d6 will count as:
111,112,113,114,115,116,121,122,123,124,125,126,131,etc.
The function accepts the sum of each, so it will read: 3,4,5,6,7,8,4,5,6,7,8,9,5, etc. He pushes all 6 ^ 3 possible results and adds 1 to the corresponding slot in the $ distribution array between 3 and 18. Pretty simple. However, it only works until 8d6, after which I get server timeouts, because now it does billions of calculations.
But I do not think this is necessary, because the probability of probability follows the distribution of the sweet bell tower. I am wondering if there is a way to skip the crunch number and go straight to the curve itself. Is there a way to do this, for example, 80d6 (range: 80-480)? Is it possible to project a distribution without doing 6 ^ 80 calculations?
I am not a professional coder, and the probability for me is still new, so thanks for the help!
Stephen