Hi,

I generated 10 random numbers ranging from 0 to maxrange to find out the running total to work out the fitness of each chromosome. Then I generated 10 more random numbers which range from 0 to the maximum of running total. The second set of 10 random numbers are to compare them to the running total (all of the running total numbers are the fittest ones of each chromosome) to find out the parent population.

What I have done in addition to this is make the last number the total value (max range), so that a random number can only be generated from 0-to maximum of running total.

Im trying to figure out how to display a number (parent population) from an array where it has been chosen by a random number (ranging 0 to maximum of running total).

For example

(Random numbers always different when program is ran)

First set of 10 random numbers for running total ranging from 0 to maxrange

11, 31, 45, 65, 36, 25, 150, 187, 70, 200

Second set of 10 random numbers ranging from 0 to maximum of running total. Each one is added with the previous number.

0 = 10

1 = 30 (+20)

2 = 32 (+2)

3 = 40 (+8)

4 = 71 (+31)

5 = 76 (+5)

6 = 100 (+24)

7 = 152 (+52)

8 = 163 (+11)

9 = 200 (+37)

So the last index number 9 equals to 200 which is the maxmum number generated for the running total.

Now

If the random number is 150, the program should display the value from index number 7 which is 152.

If the random number is 70, the program should display the value from index number 4 which is 71.

(I am looping this 10 times, so 10 random numbers are generated.)

This is where the problem comes in I can't seem to display the value from index 7.

Basically I have worked out the fitness of each chromosome but need to select the parent population from the roulette wheel. It is the roulette wheel part of my code which i cant seem to get my head around.

Can someone point me in the right direction please. Would appreciate it a lot.

Here is my code fo my roulette wheel.

```
//------------------------------------------------------------------------------
//Roulette_Wheel
void roulette_wheel(int fitness [population], char chromosome[population][chromelength], char parent[population][chromelength])
{
int i;
int j;
int k;
int max_fitness;
int random;
int running_total[population];
int current_total;
//int chromosome[population];
//int parent[population];
current_total = 0;
for (i=0; i<population; i++)
{
current_total = fitness[i] + current_total;
running_total[i] = current_total;
cout<<"Running Total ["<<i<<"] "<<running_total[i]<<endl;
// cout<<"Current Total "<<current_total<<endl;
}
cout<<endl;
max_fitness = current_total;
cout<<"Max Fitness = "<<max_fitness;
cout<<endl;
for (i=0; i<population; i++)
{
cout<<endl;
random = My_rand_no(max_fitness);
cout<<"Random Number = "<<random<<endl;
cout<<endl;
for (j=0; j<population; j++)
{
if (random > running_total[j])
for (k=0; k < chromelength; k++)
{
parent[i][k] = chromosome[j][k];
j = population + 1;
cout<<"Parent ["<<i<<"] = "<current_total[j] <<endl;
}
}
}
}
```

If the post is unclear, please say so and I will try elaborate abit more.

Thank you