XII Release 0.1.0
Loading...
Searching...
No Matches
xiiRandom Class Reference

Copyright (c) Theophilus Eriata. All Rights Reserved. More...

#include <Random.h>

Public Member Functions

void Initialize (xiiUInt64 uiSeed)
 Initializes the RNG with the given seed value. The value should not be zero.
void InitializeFromCurrentTime ()
void Save (xiiStreamWriter &inout_stream) const
 Serializes the current state.
void Load (xiiStreamReader &inout_stream)
 Deserializes the current state.
xiiUInt32 UInt ()
 Returns a uint32 value, ie. ranging from 0 to (2 ^ 32) - 1.
xiiUInt32 UIntInRange (xiiUInt32 uiRange)
xiiUInt32 UInt32Index (xiiUInt32 uiArraySize, xiiUInt32 uiFallbackValue=xiiInvalidIndex)
xiiUInt16 UInt16Index (xiiUInt16 uiArraySize, xiiUInt16 uiFallbackValue=0xFFFF)
xiiInt32 IntMinMax (xiiInt32 iMinValue, xiiInt32 iMaxValue)
 Returns an int32 value in range [iMinValue ; iMaxValue].
XII_ALWAYS_INLINE bool Bool ()
 Returns a boolean either being true or false.
XII_ALWAYS_INLINE double DoubleZeroToOneExclusive ()
 Returns a value in range [0.0 ; 1.0), ie. including zero, but excluding one.
XII_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].
double DoubleVariance (double fValue, double fVariance)
 Returns a double value around fValue with a given variance (0 - 1 range).
double DoubleVarianceAroundZero (double fAbsMaxValue)
 Returns a double value between [-fAbsMaxValue; +fAbsMaxValue] with a Gaussian distribution.
XII_ALWAYS_INLINE float FloatZeroToOneExclusive ()
 Returns a value in range [0.0 ; 1.0), ie. including zero, but excluding one.
XII_ALWAYS_INLINE float FloatZeroToOneInclusive ()
 Returns a value in range [0.0 ; 1.0], ie. including zero and one.
XII_ALWAYS_INLINE float FloatMinMax (float fMinValue, float fMaxValue)
 Returns a float value in range [fMinValue ; fMaxValue].
XII_ALWAYS_INLINE float FloatVariance (float fValue, float fVariance)
 Returns a float value around fValue with a given variance (0 - 1 range).
XII_ALWAYS_INLINE float FloatVarianceAroundZero (float fAbsMaxValue)
 Returns a float value between [-fAbsMaxValue; +fAbsMaxValue] with a Gaussian distribution.

Detailed Description

Copyright (c) Theophilus Eriata. All Rights Reserved.

A random number generator. Currently uses the WELL512 algorithm.

Member Function Documentation

◆ DoubleMinMax()

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

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

Todo
Probably not correct

◆ DoubleVariance()

double xiiRandom::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 xiiRandom::DoubleVarianceAroundZero ( double fAbsMaxValue)

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

Todo
Test whether this is actually correct

◆ InitializeFromCurrentTime()

void xiiRandom::InitializeFromCurrentTime ( )

Initializes the RNG using current time stamp. Not very sophisticated, but good enough for things that do not need to be secure.

◆ UInt16Index()

xiiUInt16 xiiRandom::UInt16Index ( xiiUInt16 uiArraySize,
xiiUInt16 uiFallbackValue = 0xFFFF )

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

Same as UInt32Index() just for 16 bit indices.

◆ UInt32Index()

xiiUInt32 xiiRandom::UInt32Index ( xiiUInt32 uiArraySize,
xiiUInt32 uiFallbackValue = xiiInvalidIndex )

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()

xiiUInt32 xiiRandom::UIntInRange ( xiiUInt32 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:
  • /home/runner/work/XII/XII/Source/Engine/Foundation/Math/Random.h
  • /home/runner/work/XII/XII/Source/Engine/Foundation/Math/Implementation/Random.cpp