number generator

Anton Vredegoor anton.vredegoor at
Sat Mar 10 17:04:31 CET 2007

Raymond Hettinger wrote:

> To make the solutions equi-probable, a simple approach is to
> recursively enumerate all possibilities and then choose one of them
> with random.choice().

Maybe it is possible to generate the possibilities by an indexing 
function and then use randint to pick one of them. I suppose this is 
like the bricks and bins problem this thread was about:

Except that the bins now have at least 1 brick in them (if we have 
positive numbers).

I posted a rather simplistic solution (but working I think) after Steven 
Taschuk made some insightful remarks. I believe it is possible to 
generate the list of numbers directly instead of permuting a list of '0' 
and '1' characters and then finding the positions of the '1' elements.


More information about the Python-list mailing list