14 m_MaxValue(a_MaxValue),
32 if (a_Points[0].m_Value != 0)
37 for (cPoints::const_iterator itr = a_Points.begin(), end = a_Points.end(); itr != end; ++itr)
39 if (itr->m_Value == LastValue)
45 ProbSum += (LastProb + itr->m_Probability) * (itr->m_Value - LastValue) / 2;
46 LastProb = itr->m_Probability;
47 LastValue = itr->m_Value;
69 for (AStringVector::const_iterator itr = Points.begin(), end = Points.end(); itr != end; ++itr)
72 if (Split.size() != 2)
77 int Value = atoi(Split[0].c_str());
78 int Prob = atoi(Split[1].c_str());
80 ((Value == 0) && (Split[0] !=
"0")) ||
81 ((Prob == 0) && (Split[1] !=
"0"))
87 Pts.emplace_back(Value, Prob);
117 size_t Mid = (Lo + Hi) / 2;
119 if (MidProbab < a_OrigValue)
132 ProbDif = (ProbDif != 0) ? ProbDif : 1;
AStringVector StringSplitAndTrim(const AString &str, const AString &delim)
Split the string at any of the listed delimiters and trim each value.
std::vector< AString > AStringVector
Class to wrap any random engine to provide a more convenient interface.
IntType RandInt(IntType a_Min, IntType a_Max)
Return a random IntType in the range [a_Min, a_Max].
void SetPoints(const cPoints &a_Points)
Sets the distribution curve using an array of [value, probability] points, linearly interpolated.
cPoints m_Cumulative
Cumulative probability of the values, sorted, for fast bsearch lookup.
cProbabDistrib(int a_MaxValue)
bool SetDefString(const AString &a_DefString)
Sets the distribution curve using a definition string; returns true on successful parse.
int Random(MTRand &a_Rand) const
Gets a random value from a_Rand, shapes it into the distribution curve and returns the value.
std::vector< cPoint > cPoints
int m_Sum
Sum of all the probabilities across all values in the domain; -1 if not set.
int MapValue(int a_OrigValue) const
Maps value in range [0, m_Sum] into the range [0, m_MaxValue] using the stored probability.