Random number generation in cerlib is designed to be as easy as possible, while providing good enough distributions. If you have special requirements, you might want to use the <random>
API from the C++ standard library directly, or any other library.
The following lists all available functions.
auto randomInt(int min, int max) -> int;
auto randomFloat(float min = 0.0f, float max = 1.0f) -> float;
auto randomDouble(double min = 0.0, double max = 1.0) -> double;
auto randomVector2(float min = 0.0f, float max = 1.0f) -> Vector2;
auto randomVector3(float min = 0.0f, float max = 1.0f) -> Vector3;
auto randomVector4(float min = 0.0f, float max = 1.0f) -> Vector4;
The input range is expected to be in [min .. max)
, meaning that the maximum value is excluded.
Faster versions are also available and begin with a fastRand...
prefix. These implement fast, but coarse random number generation using a FastRand algorithm.
void seedFastRand(int value);
auto fastRandInt() -> int;
auto fastRandInt(int min, int max) -> int;
auto fastRandInt(const IntInterval& interval) -> int;
auto fastRandFloatZeroToOne() -> float;
auto fastRandFloat(float min, float max) -> float;
auto fastRandFloat(const FloatInterval& interval) -> float;
auto fastRandAngle() -> float;
auto fastRandAngleVector2() -> Vector2;
auto fastRandAngleVector3() -> Vector3;
auto fastRandAngleVector4() -> Vector4;