def random_partition(n, s):
    partition = [0] * s
for x in range(n):
    partition[random.randrange(s)] += 1
return partition
An algorithm for randomly generating integer partitions of a particular length, in Python?