int bestpro(int a[], int val)
{
int count = 0, n;
int l[4];
for(int i=0; i < JOBS; i++)
{
if (a[i] == val)
count++;
}
if (count >= 2)
{
for(int i=0; i<JOBS; i++)
{
if (a[i] == val)
l[i] = 1;
else
l[i] = 0;
}
}
else
{
for(int i=0; i < JOBS; i++)
{
if (a[i] == val)
return i;
elsecontinue;
}
}
}
here i have to select a random number for which l[i] = 1. i.e. to select a random index i for which l[i] = 1... so i have to return the index basically.
AND value of JOBS = 4...
Suppose for i = 0,2,3 l[i] = 1, i have to select a random number from 0, 2 and 3 and return it...
And i use this function in a loop, so it is executed a number of times and each time the values are different.. like in the next loop, l[i] = 1 for 1 and 3, so i have to select a random number from 1 and 3 and return that.