Ive got a class Population with its constructor:
private Individual[] m_population;
public Population() {
m_population = new Individual[POP_SIZE];
for (int i = 0; i < POP_SIZE; i++) {
m_population[i] = new Individual();
m_population[i].randGenes();
}
//some other code here
}
Inside the Individual class I have the method for randGenes():
Random rand2 = new Random((int) DateTime.Now.Ticks & 0x0000FFFF);
public void randGenes()
{
for (int i = 0; i < SIZE; ++i)
{
for (int j = 0; j < SIZE; j++)
{
this.setGene(i, j, rand2.Next(1));
}
}
}
I just need a set of 25 radnom 1s and 0s for each of the 10 individuals. But I always get the same set for each of the 10 individuals, when I fiddle even more with it I only get 0s. Its only when I enter debug mode that I get truly random numbers. I see everywhere that the new random should be created outside the method and/or the loop, which I did so I dont know what to do next?
Aucun commentaire:
Enregistrer un commentaire