MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions
MFM::Random Class Reference

#include <Random.h>

Public Member Functions

 Random ()
 
 Random (u32 seed)
 
u32 Create ()
 
u32 Create (u32 max)
 
bool CreateBool ()
 
bool OneIn (u32 odds)
 
bool OddsOf (u32 thisMany, u32 outOfThisMany)
 
template<int P>
bool OddsOf (FXP< P > thisMany, FXP< P > outOfThisMany)
 
s32 Between (s32 min, s32 max)
 
void SetSeed (u32 seed)
 

Detailed Description

An interface for easy PRNG interaction.

Constructor & Destructor Documentation

MFM::Random::Random ( )
inline

Creates a new Random instance that is ready to be used.

MFM::Random::Random ( u32  seed)
inline

Creates a new Random instance, initialized using a specified seed.

Member Function Documentation

s32 MFM::Random::Between ( s32  min,
s32  max 
)
inline

Return a uniformly chosen pseudo-random signed number in the range of min..max, with both endpoints included. between(-1,1) returns -1, 0, and 1 equally often. FAILs with ILLEGAL_ARGUMENT if max<min.

u32 MFM::Random::Create ( )
inline

Gets 32 well-mixed pseudo-random bits from this internal PRNG .

Returns
a 32-bit word containing pseudo-random bits.
u32 MFM::Random::Create ( u32  max)
inline

Gets a uniform pseudo-random number from 0..max-1. FAILs ILLEGAL_ARGUMENT if max==0.

Parameters
maxThe exclusive upper bound of the generated number.
Returns
A pseudo-random number in the range [0, max) .
bool MFM::Random::CreateBool ( )
inline

Generates a pseudo-random boolean value.

Returns
Either true or false , determined pseudo-randomly.
bool MFM::Random::OddsOf ( u32  thisMany,
u32  outOfThisMany 
)
inline

Return true pseudo-randomly. with thisMany times outOfThisMany times. E.g., oddsOf(1,10) returns true on 10% of calls. When thisMany == 0, never returns true. When thisMany >= outOfThisMany, always returns true. FAILs ILLEGAL_ARGUMENT if outOfThisMany is 0.

template<int P>
bool MFM::Random::OddsOf ( FXP< P >  thisMany,
FXP< P >  outOfThisMany 
)
inline

Return true pseudo-randomly, with fixed point bounds. E.g., oddsOf(FXP16(0.6),FXP16(2)) returns true on 30% of calls. FAILs ILLEGAL_ARGUMENT if outOfThisMany is <= 0. When thisMany <= 0, never returns true. When thisMany >= outOfThisMany, always returns true.

bool MFM::Random::OneIn ( u32  odds)
inline

Return true pseudo-randomly. with a chance of 1-in-odds. E.g., oneIn(10) returns true on 10% of calls. When odds == 1, always returns true. FAILs ILLEGAL_ARGUMENT if odds is 0.

void MFM::Random::SetSeed ( u32  seed)
inline

Resets the seed for the PRNG to a given seed.

Parameters
seedThe seed to set the internal PRNG to.

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