number generator

Carsten Haese carsten at uniqsys.com
Fri Mar 9 16:42:48 CET 2007


On Fri, 2007-03-09 at 07:17 -0800, cesco wrote:
> On Mar 9, 3:51 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> > "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?
> >
> > Erm, yes, lots of ways, there are probably further constraints on the
> > problem, such as the size of the integers, how the lists are supposed
> > to be distributed, etc.  Can you be more specific?  Is this for an
> > application?  If it's a homework problem, that's fine, but it's better
> > in that case for respondents to suggest hints rather than full solutions.
> 
> 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.

Paul still had a point, since the word "positive" is a vital piece of
information that never appeared in your original description.

-Carsten





More information about the Python-list mailing list