Rebel Fork Framework
Urho3D::RandomEngine Class Reference

Random number generator. Stable across platforms and runs for any given seed. More...

#include <Urho3D/Math/RandomEngine.h>

Public Types

using EngineType = std::minstd_rand
 Underlying random engine type.
 

Public Member Functions

 RandomEngine ()
 Construct with random seed.
 
 RandomEngine (unsigned seed)
 Construct with seed.
 
 RandomEngine (const ea::string &state)
 Construct from state.
 
void Load (const ea::string &state)
 Load state from string.
 
ea::string Save () const
 Save state as string.
 
unsigned GetUInt ()
 Return random unsigned integer number in range [0, MaxRange) with uniform distribution.
 
unsigned GetUInt (unsigned range)
 Return random unsigned integer number in range [0, range) with uniform distribution. Range should not exceed MaxRange.
 
unsigned GetUInt (unsigned min, unsigned max)
 Return random unsigned int in range [min, max) with uniform distribution. Range should not exceed MaxRange.
 
int GetInt (int min, int max)
 Return random int in range [min, max) with uniform distribution. Range should not exceed MaxRange.
 
template<class RandomIter >
void Shuffle (RandomIter first, RandomIter last)
 Shuffle range in random order.
 
double GetDouble ()
 Return random double in range [0, 1] with uniform distribution.
 
double GetDouble (double min, double max)
 Return random double in range [min, max] with uniform distribution.
 
bool GetBool (float probability)
 Return random boolean with given probability of returning true.
 
float GetFloat ()
 Return random float in range [0, 1] with uniform distribution.
 
float GetFloat (float min, float max)
 Return random float in range [min, max] with uniform distribution.
 
ea::pair< float, float > GetStandardNormalFloatPair ()
 Return pair of random floats with standard normal distribution.
 
float GetStandardNormalFloat ()
 Return random float with standard normal distribution.
 
float GetNormalFloat (float mean, float sigma)
 Return random float with normal distribution.
 
Vector2 GetDirectionVector2 ()
 Return random 2D direction (normalized).
 
Vector3 GetDirectionVector3 ()
 Return random 3D direction (normalized).
 
Quaternion GetQuaternion ()
 Return random quaternion (normalized).
 
Vector2 GetVector2 (const Vector2 &min, const Vector2 &max)
 Return random 2D vector in 2D volume.
 
Vector3 GetVector3 (const Vector3 &min, const Vector3 &max)
 Return random 3D vector in 3D volume.
 
Vector3 GetVector3 (const BoundingBox &boundingBox)
 Return random 3D vector in 3D volume.
 

Static Public Member Functions

static RandomEngineGetDefaultEngine ()
 Return default thread-local random engine.
 
static constexpr unsigned MaxRange ()
 Return random generator range (2147483646).
 

Static Public Attributes

static const unsigned MaxIterations = 32
 Max number of tries to produce "good" random values.
 

Private Member Functions

void GetStandardNormalFloatArray (ea::span< float > array)
 Return random array of floats with standard normal distribution.
 
void GetDirection (ea::span< float > direction)
 Return random N-dimensional direction (normalized).
 

Private Attributes

EngineType engine_
 Underlying engine.
 

Detailed Description

Random number generator. Stable across platforms and runs for any given seed.


The documentation for this class was generated from the following files: