def random_population(genome_alphabet, genome_size, num_organisms, fitness_calculator):
 all_orgs = []
 letter_rand = random.Random()
 if isinstance(genome_alphabet.letters[0], str):
  if (sys.version_info[0] == 3):
   alphabet_type = 'u'
  else:
   alphabet_type = 'c'
 elif isinstance(genome_alphabet.letters[0], int):
  alphabet_type = 'i'
 elif isinstance(genome_alphabet.letters[0], float):
  alphabet_type = 'd'
 else:
  raise ValueError(('Alphabet type is unsupported: %s' % genome_alphabet.letters))
 for org_num in range(num_organisms):
  new_genome = MutableSeq(array.array(alphabet_type), genome_alphabet)
  for gene_num in range(genome_size):
   new_gene = letter_rand.choice(genome_alphabet.letters)
   new_genome.append(new_gene)
  all_orgs.append(Organism(new_genome, fitness_calculator))
 return all_orgs

def random_population ( genome_alphabet , genome_size , num_organisms , fitness_calculator ) : all_orgs = [ ] letter_rand = random . Random ( ) if isinstance ( genome_alphabet . letters [ 0 ] , str ) : if ( sys . version_info [ 0 ] == 3 ) : alphabet_type = 'u' else : alphabet_type = 'c' elif isinstance ( genome_alphabet . letters [ 0 ] , int ) : alphabet_type = 'i' elif isinstance ( genome_alphabet . letters [ 0 ] , float ) : alphabet_type = 'd' else : raise ValueError ( ( 'Alphabet type is unsupported: %s' % genome_alphabet . letters ) ) for org_num in range ( num_organisms ) : new_genome = MutableSeq ( array . array ( alphabet_type ) , genome_alphabet ) for gene_num in range ( genome_size ) : new_gene = letter_rand . choice ( genome_alphabet . letters ) new_genome . append ( new_gene ) all_orgs . append ( Organism ( new_genome , fitness_calculator ) ) return all_orgs
generate a population of individuals with randomly set genomes .