number generator

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Fri Mar 9 11:16:04 EST 2007


cesco wrote:
> On Mar 9, 3:51 pm, Paul Rubin <http://phr...@NOSPAM.invalid>
>> "cesco" <fd.calabr... at gmail.com> writes:
>>> 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?

Isn't at least one of those numbers depending on the others?

> Given two positive integers, N and M with N < M, I have to
> generate N positive integers such that sum(N)=M. No more
> constraints.

Then why must they be random? div and mod should do it.

Regards,


Björn

-- 
BOFH excuse #220:

Someone thought The Big Red Button was a light switch.




More information about the Python-list mailing list