Source:
import random

def distribute_random(n):
    l = [random.uniform(0,1) for _ in xrange(n)]
    t = sum(l)
    return [i / t for i in l]
Sample Usage:
# to test
d = distribute_random(5)
print d, sum(d)

Generate a list of random numbers that totals to 1

Pythoneer 6 years ago