I wrote:
> V is a vector of POSITIVE integers with shape N whose sum is Q.
Minor correction "... with length N ... " (obviously shape is always a
vector, so the shape would be ,N).
> If we knew the number ZFNP of possible 0-free N-partitions
> an integer Q, then we'd only have to roll ?ZFNP and then
> figure out some function analogous to #: to break it apart
> into its constituents.
OK, so after a little googling, I'm not looking for Q's partitions, but its
compositions. The difference is the same between a combination and a
permutation: two partitions with the same elements but a different
ordering are considered the "same" parition; two compositions with the
same elements but a different ordering are considered "different"
compositions.
According to Mathworld [1], the number of compositions of y into x parts
(where 0 is not allowed as a part) is given by:
(!<:y)%(!<:x)*(!y-x)
or plain old:
! * %
For example, the table I posted earlier with N=3 and Q=7 had 15 rows:
3 (! * %) 7
15
So now we can choose:
rci =: [: ? ! * % NB. Random Composition Index
For example:
3 rci 7
14
3 rci 7
13
3 rci 7
8
Now we just have to figure out how turn 14 into 5 1 1 and 3 into 1 4 2 and
8 into 2 4 1 .
-Dan
[1] Wolfram Mathworld entry on Integer Compositions:
http://mathworld.wolfram.com/Composition.html
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm