Using the functions from this answer you can generate a list of x random numbers that sum to y.
Iterate over the items of this list and make that many random choices (with removal) from a population of elements for each holder.
Or by example:
# requires RandIntVec() & RandFloats() from linked answer
# whatever population you are choosing from, example letter
population = list('qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890')
# sizes (whatever you want)
num_of_holders = 7
total_elements = len(population)
# empty holder to put results in
element_holder = [[] for _ in xrange(num_of_holders)]
# distribute total_elements elements in randomly-sized portions among num_of_holders 'element holders'
random_portions_in_holder = RandIntVec(num_of_holders, total_elements, Distribution=RandFloats(num_of_holders))
# assign each portion of elements to each 'holder'
for h, portion in enumerate(random_portions_in_holder):
for p in range(portion):
index = random.randrange( len(population) )
element_holder[h].append(population.pop(index))
# display
print 'Randomly-portioned elements'
for h in element_holder:
print h
# verify
print '\nMatch desired result?'
print 'total_elements :', total_elements
print 'elements in holders :', sum([len(h) for h in element_holder])
print 'match :', total_elements == sum([len(h) for h in element_holder])
output
Randomly-portioned elements
['M', 'N', 'f', 'V', 'v', 'h', 'i', 'H', '6', '5', 'j', '7', 'r']
['u', 'Z', 'C', 'I', 's', 'm', 'g', 'p', 'q', 'a', 'O', 'T', 'L']
['K', 'E', 'P', 'U']
['Y', 'D', 'A', 'l', 'J', 'R', 'b', 'c', 'z', 'F']
['0', '1', 'o', 'X', 'G', '4', 'W', '3', '2']
['d', 'Q']
['e', 'y', 'B', '8', 'x', 'k', 'w', 't', 'S', 'n', '9']
Match desired result?
total_elements : 62
elements in holders : 62
match : True
P.S. I had some indentation errors when I copied the linked functions, you may need to correct them. The code under elif Distribution.lower() == 'normal':
needs to by un-indented by 1 level. I submitted an edited version (ending approval), so depending on when you copy, you may or may not need to edit.