very simple Genetic Algorithm completed
Carl Banks
pavlovevidence at gmail.com
Fri Feb 1 14:57:23 EST 2008
More information about the Python-list mailing list
Fri Feb 1 14:57:23 EST 2008
- Previous message (by thread): very simple Genetic Algorithm completed
- Next message (by thread): very simple Genetic Algorithm completed
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Feb 1, 9:09 am, Paul McGuire <pt... at austin.rr.com> wrote: > 2. Bugfix: In 2 places, change: > newgene=genes[randint(0,14)-1] > to > newgene=genes[randint(0,14-1)] > > randint(a,b) returns values from a to b inclusive, and genes is a list > containing 14 elements (so you want subscripts from 0 to 13). (Using > subscripts from -1 to 13 will bias the selection of genes to use twice > as many of the last item in the list, since both -1 and 13 will give > that value.) Better yet, use random.randrange: it was added for this very reason, to get a random index in a range. Perhaps even better still, use random.choice. It gets a random element in a sequence. Carl Banks
- Previous message (by thread): very simple Genetic Algorithm completed
- Next message (by thread): very simple Genetic Algorithm completed
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list