On Mar 9, 10:44 pm, "cesco" <[EMAIL PROTECTED]> wrote: > I have to generate a list of N random numbers (integer) whose sum is > equal to M. If, for example, I have to generate 5 random numbers whose > sum is 50 a possible solution could be [3, 11, 7, 22, 7]. Is there a > simple pattern or function in Python to accomplish that? > > Thanks and regards > Francesco
import random def genRandList(n,left): L = [] if n > left: return L while n: L.append(int(random.random()*(left-n+1))+1) n -= 1; left -= L[-1] return L -- http://mail.python.org/mailman/listinfo/python-list