Pirate booty distribution's distribution function I would like to know if the following multivariate discrete distribution has an established name and how to generate it.
Let the sample $(X_i)_{i\in{1..n}}$ drawn from this distribution have the following properties:


*

*$X_i \in \{0, 1, ..., m\}, \forall i \in \{1, ..., n\}$, $m \in \mathbb{N}$

*$\sum_{i=1}^n X_i = m$

*all the ($X_i$) combinations are equiprobable.


Think of it as the repartition of a pirate booty: there are $m$ items ordered by price to be distributed among $n$ pirates. The captain takes the $X_1$ most expensive items (from none to the whole booty), the captain in second takes the following $X_2$ most expensive items from the remaining booty and so on.
The analogy with the pirates stops here. Because of the third condition above, the marginalized probability of $X_1$ being 0 must be the same as that of $X_n$, which is unlikely to happen with pirates !
 A: Define $Y_i=X_i+1$.  The $Y_i$ therefore are a sequence of $n$ strictly positive integers that sum to $n+m$.  Such a sequence is called a composition of $m+n$.  
Any composition corresponds to another sequence $(k)=k_0, k_1, \ldots, k_n$ of $n+1$ integers with
$$0=k_0 \lt k_1\lt k_2 \lt \cdots \lt k_{n-1}\lt k_n=n+m.$$
The correspondence is that $k_i$ is the partial sum
$$k_i = Y_1+Y_2+\cdots+Y_i$$
and each of the original values $X_i$ can be recovered as $$X_i = k_{i}-k_{i-1}-1;\quad i=1,2,\ldots,n.$$
Now any such sequence $(k)$ determines and is determined by the subset $\{k_1,k_2,\ldots, k_{n-1}\}$ of $\{1,2,\ldots, n+m-1\}$.  There are (by definition) $\binom{n+m-1}{n-1}$ such subsets.  
Your distribution is uniform on these subsets.  It is, in effect, the distribution of samples of $1, 2, \ldots, n+m-1$ of size $n-1$ taken without replacement.
We may therefore draw the $X_i$ by selecting such a sample at random, sorting its values (to produce the $k_i$), computing their differences, and subtracting $1$ from each.  There are many well-known ways to obtain such samples, so I won't dwell on that detail.  (For efficiency, you might want to select a method that produces the sample already in sorted order.)

Here is working code in R to produce a single such realization of the $X_i$.  It calls on the sample.int function to obtain a random sample without replacement.
#
# Random compositions of `m` into `n` parts of size 0 or larger.
#
rcomposition <- function(m, n)
  diff(c(0, sort(sample.int(m+n-1, n-1)), n+m)) - 1

As an example of its use, the next code snippet specifies values of $n$ and $m$ and (reproducibly) requests 1000 realizations of the $X_i$, storing them in successive columns of the output array x:
n <- 3
m <- 4
set.seed(17)
x <- replicate(1e3, rcomposition(m, n))

We can check the output for uniformity by tallying the number of appearances of each composition.
#
# Tally the columns of `x`.
#
i <- table(apply(x, 2, paste0, collapse=ifelse(m > 9, ",", "")))
N <- choose(m+n-1, n-1)
i <- c(i, rep(0, N - length(i))) # Include any zero counts explicitly
if (length(i) <= 80) print(i)

Here's the output for this particular simulation.  The print statement displayed the tally of all $\binom{3+4-1}{3-1}=15$ possible compositions:
004 013 022 031 040 103 112 121 130 202 211 220 301 310 400 
 58  69  85  68  69  69  64  60  69  73  64  59  70  69  54 

The top row shows the compositions; for instance, the first entry 004 corresponds to $X_1=X_2=0,\ X_3=4$.  The bottom row gives their counts.
There is variation in the counts because this is, after all, a random process.  Is the amount of variation acceptable?  A chi-squared test works well for large simulations (more than $5\binom{n+m-1}{n-1}$ will do fine).
#
# Check the tally for uniformity.
#
chisq.test(i, p=rep(1/N, N))

Here is the result for this particular simulation:

X-squared = 11.54, df = 14, p-value = 0.6432

The p-value is not extremely small, showing the counts do not differ significantly from uniformity.
