I got an error at 'target.Push(i)' .
I guess in extreme cases, the result of "GetRandomFloat (-1.0,1.0) " can be 0.0, so the 'ArrayList target' will remain as "null",which can cause error when "target.Push(i)"
Code:
ArrayList smalls = new ArrayList(2);
ArrayList bigs = new ArrayList(2);
int small_i = 0;
int big_i = 0;
for(int i = 0; i < len; ++i) {
float weight = weights.Get(i);
if(weight == avg)
{
weight += GetRandomFloat(-1.0, 1.0);
}
bool is_small = (weight < avg);
bool is_big = (weight > avg);
ArrayList target = null;
int target_i = -1;
if(is_small)
{
target = smalls;
target_i = small_i;
}
else if(is_big)
{
target = bigs;
target_i = big_i;
}
target.Push(i);
if(weight > 0.0 && avg > 0.0) {
weight = weight/avg;
} else {
weight = 0.0;
}
target.Set(target_i, weight, 1);
if(is_small) {
++small_i;
} else if(is_big) {
++big_i;
}
}
I made a simple fix.
Code:
if(weight == avg)
{
weight += GetRandomInt(0,99) < 50? 0.00001:-0.00001;
}