Hi, another way to look at this is to obtain the generating function based on integer partitioning. Basically we are trying to put 172 balls into six bins with the restriction that each bin receive at least 1 ball and no more than 70. The number of valid combinations is probably a big number but nonetheless a finite number, say B. We can thus "name" each combination using the integers from 1 to B. Choosing n set of 6 random integers can be expressed as choosing n random integers from 1 to B and generating the six numbers identified by the n random integers. This is similar to what the anagram function does :
3 2 5 A. 'abc' bca bac cba The problem has morphed into finding the generating function. This might take me some time. Jimmy On Tue, Jun 26, 2018 at 10:12 AM, Skip Cave <s...@caveconsulting.com> wrote: > I want to generate n sets of 6 random integers from 1->70 where each set of > 6 integers sums to 172 > > Here's my first try: > > ts =: 3 : 0 > > b=: 2 6$0 > > for. i.y do. a=:1+6?70 > > b=:b,a > > end. > > b#~172=+/"1 b > > ) > > Test it: > > ts 1000 > > 27 60 5 24 53 3 > > 38 35 3 15 57 24 > > 16 29 19 50 4 54 > > This generates some 6-element vectors that sum to 172 by elimination, but I > don't have control of how many vectors it produces. > > > I want to change the logic in the loop so that it keeps generating sets of > 6 random integers, testing whether they sum to 172, saving just the sets > that sum to 172, until I have saved y random sets that sum to 172, and then > exits. > > > Any help would be appreciated. > > > Skip > > > Skip Cave > Cave Consulting LLC > > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm