corrected getWeightedRandomValue