My understanding is that the function is something like this:
Code:
int random(int weights[], int start, int end);
so you would get a random index depending on an array of weights.
Something like:
Code:
int random(vector<int>& weights)
{
int total = 0, found;
int len = weights.size();
int w[] = new int[len]
for (int i = 0; i < len ; ++i) {
total += weights[i];
w[i] = total;
}
int index = rand() % total;
for (int i = 0; i < len ; ++i)
if (total < w[i]) {
found = i;
break;
}
delete w;
return found;
}
So you would select a random index from 0 to weights.size().
The "index" shows the index selected if you would expand the array as shown on post #2.