I want to randomly generate a sequence of 10 integers in the range [-2, 2] that add up to 1.
The distribution of the outcome isn't important. I just want the sequence to be random and the sum guaranteed to be the value I want.
(Scanning previous questions... I might be able to craft this answer to suit my needs, but maybe not: How to efficiently generate five numbers that add to one? )
EDIT: I added "efficiently" because I could just roll the dice over and over until I get a sequence with the right sum, but how is that fun?
EDIT: Even though I don't care if there's a bias in picking a particular sequence, Anthony Carapetis's comment makes me think that insisting on a fair selection -- where any possible solution is as likely as any other -- actually makes the problem easier. I'm going to race down that path today and see where it leads.
There are $837,100$ sequences that add to $1$ out of the $5^{10}=9,765,625$ total sequences. You could write a small program to generate all the sequences, add each one up, and write the ones that sum to $1$ to a file. Then generate a random number in the range $[0,837099]$ and use that one.
If you precalculate the "Pascal's triangle" you can use it to go from a number in $[0,837099]$ to a sequence. Of the $837100$ that add to $1$, there are $142740$ that finish with $-2$, $162585$ that end in $-1$, $175725$ that end in $0$, $180325$ that end in $1$, and $162585$ that end in $2$. You can test against these values to determine the last element of the sequence, then work your way back to the front. So if you want sequence $400000,$ it ends with $0$ as $142470+162585+180325 \gt 400000 \gt 142470+162585$ and it is the $94675^{\text{th}}$ of those. The first nine elements add to $1$. Of the $175725$ nine element sequences that sum to $1$, the first $37080+38165=75245$ end with $2$ or $1$, so we want the $19430^{\text{th}}$ sequence that ends in $00$ and so on.