ezEngine  Release 25.03
ezRandom Class Reference

A random number generator. Currently uses the WELL512 algorithm. More...

#include <Random.h>

Public Member Functions

void Initialize (ezUInt64 uiSeed)
 Initializes the RNG with the given seed value. The value should not be zero.
 
void InitializeFromCurrentTime ()
 Initializes the RNG using current time stamp. Not very sophisticated, but good enough for things that do not need to be secure.
 
void Save (ezStreamWriter &inout_stream) const
 Serializes the current state.
 
void Load (ezStreamReader &inout_stream)
 Deserializes the current state.
 
ezUInt32 UInt ()
 Returns a uint32 value, ie. ranging from 0 to (2 ^ 32) - 1.
 
ezUInt32 UIntInRange (ezUInt32 uiRange)
 Returns a uint32 value in range [0 ; uiRange - 1]. More...
 
ezUInt32 UInt32Index (ezUInt32 uiArraySize, ezUInt32 uiFallbackValue=ezInvalidIndex)
 Returns a random uint32 in range [0 ; uiArraySize - 1]. More...
 
ezUInt16 UInt16Index (ezUInt16 uiArraySize, ezUInt16 uiFallbackValue=0xFFFF)
 Returns a random uint16 in range [0 ; uiArraySize - 1]. More...
 
ezInt32 IntMinMax (ezInt32 iMinValue, ezInt32 iMaxValue)
 Returns an int32 value in range [iMinValue ; iMaxValue].
 
EZ_ALWAYS_INLINE bool Bool ()
 Returns a boolean either being true or false.
 
EZ_ALWAYS_INLINE double DoubleZeroToOneExclusive ()
 Returns a value in range [0.0 ; 1.0), ie. including zero, but excluding one.
 
EZ_ALWAYS_INLINE double DoubleZeroToOneInclusive ()
 Returns a value in range [0.0 ; 1.0], ie. including zero and one.
 
double DoubleMinMax (double fMinValue, double fMaxValue)
 Returns a double value in range [fMinValue ; fMaxValue]. More...
 
double DoubleVariance (double fValue, double fVariance)
 Returns a double value around fValue with a given variance (0 - 1 range) More...
 
double DoubleVarianceAroundZero (double fAbsMaxValue)
 Returns a double value between [-fAbsMaxValue; +fAbsMaxValue] with a Gaussian distribution. More...
 
EZ_ALWAYS_INLINE float FloatZeroToOneExclusive ()
 Returns a value in range [0.0 ; 1.0), ie. including zero, but excluding one.
 
EZ_ALWAYS_INLINE float FloatZeroToOneInclusive ()
 Returns a value in range [0.0 ; 1.0], ie. including zero and one.
 
EZ_ALWAYS_INLINE float FloatMinMax (float fMinValue, float fMaxValue)
 Returns a float value in range [fMinValue ; fMaxValue].
 
EZ_ALWAYS_INLINE float FloatVariance (float fValue, float fVariance)
 Returns a float value around fValue with a given variance (0 - 1 range)
 
EZ_ALWAYS_INLINE float FloatVarianceAroundZero (float fAbsMaxValue)
 Returns a float value between [-fAbsMaxValue; +fAbsMaxValue] with a Gaussian distribution.
 

Detailed Description

A random number generator. Currently uses the WELL512 algorithm.

Member Function Documentation

◆ DoubleMinMax()

double ezRandom::DoubleMinMax ( double  fMinValue,
double  fMaxValue 
)

Returns a double value in range [fMinValue ; fMaxValue].

Todo:
Probably not correct

◆ DoubleVariance()

double ezRandom::DoubleVariance ( double  fValue,
double  fVariance 
)

Returns a double value around fValue with a given variance (0 - 1 range)

Todo:
Test whether this is actually correct

◆ DoubleVarianceAroundZero()

double ezRandom::DoubleVarianceAroundZero ( double  fAbsMaxValue)

Returns a double value between [-fAbsMaxValue; +fAbsMaxValue] with a Gaussian distribution.

Todo:
Test whether this is actually correct

◆ UInt16Index()

ezUInt16 ezRandom::UInt16Index ( ezUInt16  uiArraySize,
ezUInt16  uiFallbackValue = 0xFFFF 
)

Returns a random uint16 in range [0 ; uiArraySize - 1].

Same as UInt32Index() just for 16 bit indices.

◆ UInt32Index()

ezUInt32 ezRandom::UInt32Index ( ezUInt32  uiArraySize,
ezUInt32  uiFallbackValue = ezInvalidIndex 
)

Returns a random uint32 in range [0 ; uiArraySize - 1].

If uiArraySize is 0, uiFallbackValue is returned instead. This is meant for generating a random index into an array. If the array is empty, no valid index can be generated, however, instead of asserting, a dedicated invalid index is returned.

This function is nearly the same as UIntInRange(), except that that function asserts that uiRange is larger than 0.

◆ UIntInRange()

ezUInt32 ezRandom::UIntInRange ( ezUInt32  uiRange)

Returns a uint32 value in range [0 ; uiRange - 1].

Note
A range of 0 is invalid and will assert! It also has no mathematical meaning. A range of 1 already means "between 0 and 1 EXCLUDING 1". So always use a range of at least 1.

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