number generator

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Sat Mar 10 08:38:31 EST 2007


On Sat, 10 Mar 2007 02:32:21 -0800, Dick Moores wrote:

> So why not just repeatedly call a function to generate lists of 
> length N of random integers within the appropriate range (the closed 
> interval [1,M-N-1]), and return the first list the sum of which is M? 
> I don't understand what all the discussion is about. Time is not one 
> of the constraints.

Time is always a constraint. The sun will expand and destroy the Earth in
a couple of billion years, it would be nice to have a solutions before
then... 

*wink*

Seriously, almost all programming problems have two implicit constraints:
it must run as fast as practical, using as little computer resources (e.g.
memory) as practical. Naturally those two constraints are usually in
opposition, which leads to compromise algorithms that run "fast enough"
without using "too much" memory.



-- 
Steven.




More information about the Python-list mailing list