diff options
author | Alexander Harkness <bearbin@gmail.com> | 2013-07-29 13:13:03 +0200 |
---|---|---|
committer | Alexander Harkness <bearbin@gmail.com> | 2013-07-29 13:13:03 +0200 |
commit | 53e22b11857fed62e2313d6d84d90f88ed412ffb (patch) | |
tree | c61e56725da7dff0154d566722651e2c39c9d6c6 /source/ProbabDistrib.h | |
parent | WebAdmin: Removed the duplicate memory usage querying (diff) | |
download | cuberite-53e22b11857fed62e2313d6d84d90f88ed412ffb.tar cuberite-53e22b11857fed62e2313d6d84d90f88ed412ffb.tar.gz cuberite-53e22b11857fed62e2313d6d84d90f88ed412ffb.tar.bz2 cuberite-53e22b11857fed62e2313d6d84d90f88ed412ffb.tar.lz cuberite-53e22b11857fed62e2313d6d84d90f88ed412ffb.tar.xz cuberite-53e22b11857fed62e2313d6d84d90f88ed412ffb.tar.zst cuberite-53e22b11857fed62e2313d6d84d90f88ed412ffb.zip |
Diffstat (limited to '')
-rw-r--r-- | source/ProbabDistrib.h | 148 |
1 files changed, 74 insertions, 74 deletions
diff --git a/source/ProbabDistrib.h b/source/ProbabDistrib.h index ac5f24894..ddaadd9b7 100644 --- a/source/ProbabDistrib.h +++ b/source/ProbabDistrib.h @@ -1,74 +1,74 @@ -
-// ProbabDistrib.h
-
-// Declares the cProbabDistrib class representing a discrete probability distribution curve and random generator
-
-/*
-Usage:
-1, Create a cProbabDistrib instance
-2, Initialize the distribution either programmatically, using the SetPoints() function, or using a definition string
-3, Ask for random numbers in that probability distribution using the Random() function
-*/
-
-
-
-
-
-#pragma once
-
-
-
-
-
-// fwd:
-class MTRand;
-
-
-
-
-
-class cProbabDistrib
-{
-public:
- class cPoint
- {
- public:
- int m_Value;
- int m_Probability;
-
- cPoint(int a_Value, int a_Probability) :
- m_Value(a_Value),
- m_Probability(a_Probability)
- {
- }
- } ;
-
- typedef std::vector<cPoint> cPoints;
-
-
- cProbabDistrib(int a_MaxValue);
-
- /// Sets the distribution curve using an array of [value, probability] points, linearly interpolated. a_Points must not be empty.
- void SetPoints(const cPoints & a_Points);
-
- /// Sets the distribution curve using a definition string; returns true on successful parse
- bool SetDefString(const AString & a_DefString);
-
- /// Gets a random value from a_Rand, shapes it into the distribution curve and returns the value.
- int Random(MTRand & a_Rand) const;
-
- /// Maps value in range [0, m_Sum] into the range [0, m_MaxValue] using the stored probability
- int MapValue(int a_OrigValue) const;
-
- int GetSum(void) const { return m_Sum; }
-
-protected:
-
- int m_MaxValue;
- cPoints m_Cumulative; ///< Cumulative probability of the values, sorted, for fast bsearch lookup
- int m_Sum; ///< Sum of all the probabilities across all values in the domain; -1 if not set
-} ;
-
-
-
-
+ +// ProbabDistrib.h + +// Declares the cProbabDistrib class representing a discrete probability distribution curve and random generator + +/* +Usage: +1, Create a cProbabDistrib instance +2, Initialize the distribution either programmatically, using the SetPoints() function, or using a definition string +3, Ask for random numbers in that probability distribution using the Random() function +*/ + + + + + +#pragma once + + + + + +// fwd: +class MTRand; + + + + + +class cProbabDistrib +{ +public: + class cPoint + { + public: + int m_Value; + int m_Probability; + + cPoint(int a_Value, int a_Probability) : + m_Value(a_Value), + m_Probability(a_Probability) + { + } + } ; + + typedef std::vector<cPoint> cPoints; + + + cProbabDistrib(int a_MaxValue); + + /// Sets the distribution curve using an array of [value, probability] points, linearly interpolated. a_Points must not be empty. + void SetPoints(const cPoints & a_Points); + + /// Sets the distribution curve using a definition string; returns true on successful parse + bool SetDefString(const AString & a_DefString); + + /// Gets a random value from a_Rand, shapes it into the distribution curve and returns the value. + int Random(MTRand & a_Rand) const; + + /// Maps value in range [0, m_Sum] into the range [0, m_MaxValue] using the stored probability + int MapValue(int a_OrigValue) const; + + int GetSum(void) const { return m_Sum; } + +protected: + + int m_MaxValue; + cPoints m_Cumulative; ///< Cumulative probability of the values, sorted, for fast bsearch lookup + int m_Sum; ///< Sum of all the probabilities across all values in the domain; -1 if not set +} ; + + + + |