number generator
Anton Vredegoor
anton.vredegoor at gmail.com
Sat Mar 10 11:04:31 EST 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:
http://groups.google.nl/group/comp.lang.python/browse_thread/thread/4782b54fa39b3bad
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.
A.
More information about the Python-list
mailing list