The random number generator base class. More...

#include "murl_util_rng.h"

Inheritance diagram for Murl::Util::Rng:

Public Member Functions

virtual ~Rng ()=default
 The destructor.
 
virtual void Seed (UInt32 seed)=0
 Seed the random number generator. More...
 
virtual UInt32 Rand ()=0
 Get a random number in the full UInt32 range. More...
 
Bool RandBool ()
 Get a random Bool value. More...
 
UInt32 RandUInt (UInt32 from, UInt32 to)
 Get a random UInt32 value within a specified range. More...
 
SInt32 RandSInt (SInt32 from, SInt32 to)
 Get a random SInt32 value within a specified range. More...
 
Real RandReal (Real from, Real to)
 Get a random Real value within a specified range. More...
 
Double RandDouble (Double from, Double to)
 Get a random Double value within a specified range. More...
 
SInt32 Draw (const UInt32Array &distribution)
 Draw an index from a distribution array. More...
 
SInt32 DrawNoReplacement (UInt32Array &distribution)
 Draw an index from a distribution array with no replacement. More...
 
SInt32 DrawNoReplacement (UInt32Array &distribution, UInt32 decrement)
 Draw an index from a distribution array with no replacement. More...
 

Protected Member Functions

 Rng ()=default
 The default constructor.
 

Detailed Description

The random number generator base class.

The base class is abstract and is implemented by the TT800, Well1024 and Marsaglia class.

Member Function Documentation

◆ Seed()

virtual void Murl::Util::Rng::Seed ( UInt32  seed)
pure virtual

Seed the random number generator.

Parameters
seedThe seed value.

Implemented in Murl::Util::Well1024, Murl::Util::TT800, and Murl::Util::Marsaglia.

◆ Rand()

virtual UInt32 Murl::Util::Rng::Rand ( )
pure virtual

Get a random number in the full UInt32 range.

Returns
The random number.

Implemented in Murl::Util::Well1024, Murl::Util::TT800, and Murl::Util::Marsaglia.

◆ RandBool()

Bool Murl::Util::Rng::RandBool ( )

Get a random Bool value.

Returns
The random Bool value.

◆ RandUInt()

UInt32 Murl::Util::Rng::RandUInt ( UInt32  from,
UInt32  to 
)

Get a random UInt32 value within a specified range.

It is supported to pass a range of from > to.

Parameters
fromThe start of the range.
toThe end of the range.
Returns
The random UInt32 value in range [from .. to].

◆ RandSInt()

SInt32 Murl::Util::Rng::RandSInt ( SInt32  from,
SInt32  to 
)

Get a random SInt32 value within a specified range.

It is supported to pass a range of from > to.

Parameters
fromThe start of the range.
toThe end of the range.
Returns
The random SInt32 value in range [from .. to].

◆ RandReal()

Real Murl::Util::Rng::RandReal ( Real  from,
Real  to 
)

Get a random Real value within a specified range.

Scales (from - to) within a 32 bit random number. It is supported to pass a range of from > to.

Parameters
fromThe start of the range.
toThe end of the range.
Returns
The random Real value in range [from .. to].

◆ RandDouble()

Double Murl::Util::Rng::RandDouble ( Double  from,
Double  to 
)

Get a random Double value within a specified range.

Scales (from - to) within a 64 bit random number. It is supported to pass a range of from > to.

Parameters
fromThe start of the range.
toThe end of the range.
Returns
The random Real value in range [from .. to].

◆ Draw()

SInt32 Murl::Util::Rng::Draw ( const UInt32Array distribution)

Draw an index from a distribution array.

The distribution array contains numbers which are defining the probability of the partition. The higher the value of the partition, the higher is the probability of drawing the partition.

Parameters
distributionAn array of partitions.
Returns
The index of the drawn partition or -1 if all partitions are zero.

◆ DrawNoReplacement() [1/2]

SInt32 Murl::Util::Rng::DrawNoReplacement ( UInt32Array distribution)

Draw an index from a distribution array with no replacement.

Draw() and set the drawn partition to zero.

Parameters
distributionAn array of partitions.
Returns
The index of the drawn partition or -1 if all partitions are zero.

◆ DrawNoReplacement() [2/2]

SInt32 Murl::Util::Rng::DrawNoReplacement ( UInt32Array distribution,
UInt32  decrement 
)

Draw an index from a distribution array with no replacement.

Draw() and decrement the drawn partition by a specified value.

Parameters
distributionAn array of partitions.
decrementThe value to decrement the drawn partition. The drawn partition is set to zero if the decrement underflows the partition.
Returns
The index of the drawn partition or -1 if all partitions are zero.

The documentation for this class was generated from the following file:
  • murl_util_rng.h


Copyright © 2011-2024 Spraylight GmbH.