# How to generate n random integers summing to x?

I am using dice to generate in my case 4 random integers summing to 12.

The trivial solution is to roll a d4 12 times, and have the total times each face is rolled be the four integers. This results most often in 3 3 3 3 and rarely results in 12 0 0 0. The probability for 0 X X X is (3/4)^12 = 0.0317. The probability for 12 0 0 0 is (1/4)^12 = 5.960E-8.

One method I have seen is rolling a d13 3 times, taking the ordered set [1, X, X, X, 13], and having the differences be the four numbers. In this case, getting a 0 X X X amounts to rolling a 1 for any roll, 1 - (12/13)^3 = 0.0769. 12 0 0 0 is rolling 13 3 times, or 4.552E-4. Both of these are significantly more probable.

The two methods are generalised to xdn and (n-1)d(x+1).

I dont know which of these (if either) results in a uniformly distributed solution, but I would prefer a method that does not grow linearly with x like the first.

• Welcome to MSE. Please use MathJax. Commented May 10, 2018 at 10:07
• Do you want to achieve that every possible quartupel appears with the same probability ? Commented May 10, 2018 at 10:17
• Yes, thats preferred. Commented May 11, 2018 at 9:26