PrevNextUpHome SophiaFramework UNIVERSE 5.3
SFXMTRandom
Class which generates a random number using the Mersenne Twister method(MT method).
#include <SFXMTRandom.h.hpp>
class SFXMTRandom;
SFMTYPEDEFCLASS(SFXMTRandom)

Description

The SFXMTRandom class generates a random number using the Mersenne Twister algorithm.

The same sequence of random numbers will be generated from the same seed.

[Caution] If stack is insufficient, ...

The SFXMTRandom class consumes about 2.5 kilo bytes of memory. If stack is insufficient, the SFXMTRandom instance will be created on heap.

Example

// if no seed is set, the elapsed time after the power is turned ON will become the seed
SFXMTRandom random;

// generate a random number between SINT32_MINIMUM and SINT32_MAXIMUM
SInt32 n1 = random.GetSInt32(); 

// set the seed
random.Randomize(3456);         

// generate a random number between 0 and UINT08_MAXIMUM
UInt08 n2 = random.GetUInt08(); 

Reference

SFXBrewRandom | SFXLCGRandom

Member

Constructor/Destructor
SFXMTRandom( UInt32 seed = 0 )
Constructor of the SFXMTRandom class.
Public Functions
Bool GetBool( Void )
Generate a random number of Bool type.
Float32 GetFloat32( Void )
Generate a random number of Float32 type.
Float64 GetFloat64( Void )
Generate a random number of Float64 type.
SInt08 GetSInt08( Void )
Generate a random number of SInt08 type.
SInt16 GetSInt16( Void )
Generate a random number of SInt16 type.
SInt32 GetSInt32( Void )
Generate a random number of SInt32 type.
SInt64 GetSInt64( Void )
Generate a random number of SInt64 type.
UInt08 GetUInt08( Void )
Generate a random number of UInt08 type.
UInt16 GetUInt16( Void )
Generate a random number of UInt16 type.
UInt32 GetUInt32( Void )
Generate a random number of UInt32 type.
UInt64 GetUInt64( Void )
Generate a random number of UInt64 type.
Void Randomize( UInt32 seed = 0 )
Set the seed for generating a random number.

SFXMTRandom::SFXMTRandom
Constructor of the SFXMTRandom class.
[ public, explicit ]
SFXMTRandom(
    UInt32 seed = 0   // seed to generate a random number
);

Description

If 0 is set to the "seed" argument, a seed is automatically set up based on the elapsed time after the device is turned on. In case that time cannot be obtained, "5489" is set to this argument.


SFXMTRandom::GetBool
Generate a random number of Bool type.
[ public ]
Bool GetBool(Void);

Description

Return the Bool-casted value of the 25th-from-lowest bit of a random number of UInt32 type.


SFXMTRandom::GetFloat32
Generate a random number of Float32 type.
[ public ]
Float32 GetFloat32(Void);

Return value

The return value takes the value from 0 to less than 1.

Description

Return the Float32-casted value of the lowest 24 bits of a random number of UInt32 type divided by 16777216.


SFXMTRandom::GetFloat64
Generate a random number of Float64 type.
[ public ]
Float64 GetFloat64(Void);

Return value

The return value takes the value from 0 to less than 1.

Description

Return the Float64-casted value of the highest 53 bits of a random number of UInt64 type divided by 9007199254740992.


SFXMTRandom::GetSInt08
Generate a random number of SInt08 type.
[ public ]
SInt08 GetSInt08(Void);

Description

Return the SInt08-casted value of the highest 8 bits of a random number of UInt32 type.


SFXMTRandom::GetSInt16
Generate a random number of SInt16 type.
[ public ]
SInt16 GetSInt16(Void);

Description

Return the SInt16-casted value of the highest 16 bits of a random number of UInt32 type.


SFXMTRandom::GetSInt32
Generate a random number of SInt32 type.
[ public ]
SInt32 GetSInt32(Void);

Description

Return the SInt32-casted value of a random number of UInt32 type.


SFXMTRandom::GetSInt64
Generate a random number of SInt64 type.
[ public ]
SInt64 GetSInt64(Void);

Description

Return the SInt64-casted value of a composition of two random numbers of UInt32 type.


SFXMTRandom::GetUInt08
Generate a random number of UInt08 type.
[ public ]
UInt08 GetUInt08(Void);

Description

Return the UInt08-casted value of the highest 8 bits of a random number of UInt32 type.


SFXMTRandom::GetUInt16
Generate a random number of UInt16 type.
[ public ]
UInt16 GetUInt16(Void);

Description

Return the UInt16-casted value of the highest 16 bits of a random number of UInt32 type.


SFXMTRandom::GetUInt32
Generate a random number of UInt32 type.
[ public ]
UInt32 GetUInt32(Void);

Description

Return a random number of UInt32 type.


SFXMTRandom::GetUInt64
Generate a random number of UInt64 type.
[ public ]
UInt64 GetUInt64(Void);

Description

Return the UInt64-casted value of a composition of two random numbers of UInt32 type.


SFXMTRandom::Randomize
Set the seed for generating a random number.
[ public ]
Void Randomize(
    UInt32 seed = 0   // seed to generate a random number
);

Description

If 0 is set to the "seed" argument, a seed is automatically set up based on the elapsed time after the device is turned on. In case that time cannot be obtained, "5489" is set to this argument.