Five identical items can be distributed over three distinct bins in 35 = 243 ways, each leading to one of these 21 distributions:
500 410 320 311 221
050 401 302 131 212
005 140 230 113 122
104 203
041 032
014 023
You'll notice that there are two mechanisms at work here: firstly the number 5 can be partitioned into a maximum of 3 parts in 5 different ways (the columns), and secondly each such partition has a number of permutations (the rows).
To enumerate the partitions with restricted number of parts, use a recursive algorithm, e.g. with 5 items and 3 bins:
5 items in 1 bin
4 items in 1 bin + recurse with 1 item in 2 bins
3 items in 1 bin + recurse with 2 items in 2 bins
2 items in 1 bin + recurse with 3 items in 2 bins
Generate only non-rising sequences like [2,2,1], not [2,1,2] or [0,2,3], by never putting a number of items in the current bin that is smaller than the number of items divided by the number of bins (that's why there's no option with 1 item in the first bin in the example above).
(Partitioning can be speeded up by using memoization.)
To calculate the probability of each partition (i.e. the number of permutations), divide the factorial of the number of bins by the product of the factorials of the number of bins with a certain number of items:
5,0,0 3! / (1! x 2!) = 3
4,1,0 3! / (1! x 1! x 1!) = 6
3,2,0 3! / (1! x 1! x 1!) = 6
3,1,1 3! / (1! x 2!) = 3
2,2,1 3! / (2! x 1!) = 3
--
21
Then, choose a random number from 1 to 21, and select the corresponding partition and its permutation; e.g. choosing 13 would mean partition [3,2,0] and its fourth permutation [2,0,3].
So instead of enumerating all (243 in the 5:3 example) options or all (21) distributions, we enumerate the (5) partitions, and maybe the (up to 6) permutations if there's no faster way to get to the n-th unique permutation. For large numbers, this should make a huge difference.
(For details and code examples for some of these steps, see this answer to a related question.)