Is there a better way of doing this?

andrew cooke andrew at acooke.org
Fri Mar 6 16:46:44 EST 2009


i have not been following this discussion in detail, so someone may have
already explained this, but it should not be necessary to actually
construct the roulette wheel to select values from it.  what you are doing
is selecting from a list where the there are different probabilities of
selecting different entries.  i am pretty sure that can be done more
efficiently than by constructing a new list with many more entries whose
aim is to simulate that (which is what the roulette wheel seems to be in
your code, if i have understood correctly).

more precisely, i think you can adapt the trick used to select a line at
random from a file by scanning the file just once.

sorry if i have misunderstood,
andrew





More information about the Python-list mailing list