Crystal AI  1.0.0
Crystal.PcgExtended Class Reference

PCG (Permuted Congruential Generator) Extended is a C# port from C++ of a part of the extended PCG family of generators presented in "PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation" by Melissa E. O'Neill. The code follows closely the one made available by O'Neill at her site: http://www.pcg-random.org/using-pcg-cpp.html To understand how exactly this generator works read this: http://www.pcg-random.org/pdf/toms-oneill-pcg-family-v1.02.pdf its a fun read, enjoy! The most important difference between this version and PCG is that the generators produced by this class can have extremely large periods (extremely!) and have configurable k-dimensional equidistribution. All this at a very small speed penalty! (Upto 1024-dimensionally equidistributed generators perform faster than System.Random, at least on the machines I have access to). Fun fact, the period of PCG Extended for _table_mask = 14 is 2^(524352) which is more than 10^(157846). To put this in context, the number particles in the known Universe is about 10^(80 to 81ish) if we also count photons that number goes up (with a lot of effort) to 10^(90ish). Now, there are estimates that say that visible matter (counting photons, energy-matter same thing...) accounts for 5% of the matter in the visible Universe, so if these estimates are correct the total visible+invisible particles/(energy particles) in the visible Universe would approximately be 10^(91). That means that this generator has a period that is 157755 orders of magnitude larger than the number of all particles in the visible Universe... Also, if the universe had an equal number of particles (to the period of PCG 14), that would mean that its mean density (at its current volume) would be so high that the entire Universe would collapse unto its weight into a black hole. More...

Public Member Functions

int Next ()
 Random integer in the interval [0, int.MaxValue]. More...
 
int Next (int maxExclusive)
 Random integer in the semi-open interval [0, maxExclusive ). More...
 
int Next (int minInclusive, int maxExclusive)
 Random integer in the interval [minInclusive , maxExclusive ). More...
 
int[] NextInts (int count)
 Array of size count of random integers in the interval [0, int.MaxValue]. More...
 
int[] NextInts (int count, int maxExclusive)
 Array of size count of random integers in the interval [0, maxExclusive ). More...
 
int[] NextInts (int count, int minInclusive, int maxExclusive)
 Array of size count of random integers in the interval [minInclusive , maxExclusive ). More...
 
uint NextUInt ()
 Random unsigned integer in the interval [0, uint.MaxValue]. More...
 
uint NextUInt (uint maxExclusive)
 Random unsigned integer in the interval [0, maxExclusive ). More...
 
uint NextUInt (uint minInclusive, uint maxExclusive)
 Random unsigned integer in the interval [minInclusive , maxExclusive ). More...
 
uint[] NextUInts (int count)
 Array of size count of unsigned integers in the interval [0, uint.MaxValue]. More...
 
uint[] NextUInts (int count, uint maxExclusive)
 Array of size count of unsigned integers in the interval [0, maxExclusive ). More...
 
uint[] NextUInts (int count, uint minInclusive, uint maxExclusive)
 Array of size count of unsigned integers in the interval [minInclusive , maxExclusive ). More...
 
float NextFloat ()
 Random single precision floating point number in the interval [0,1]. More...
 
float NextFloat (float maxInclusive)
 Random single precision floating point number in the interval [0, maxInclusive ]. More...
 
float NextFloat (float minInclusive, float maxInclusive)
 Random single precision floating point number in the interval [minInclusive , maxInclusive ]. More...
 
float[] NextFloats (int count)
 Array of size count of single precision floating point random numbers in the interval [0,1]. More...
 
float[] NextFloats (int count, float maxInclusive)
 Array of size count of single precision floating point random numbers in the interval [0, maxInclusive ]. More...
 
float[] NextFloats (int count, float minInclusive, float maxInclusive)
 Array of size count of single precision floating point random numbers in the interval [minInclusive , maxInclusive ]. More...
 
double NextDouble ()
 Random double precision floating point number in the interval [0, 1]. More...
 
double NextDouble (double maxInclusive)
 Random double precision floating point number in the interval [0, maxInclusive ]. More...
 
double NextDouble (double minInclusive, double maxInclusive)
 Random double precision floating point number in the interval [minInclusive , maxInclusive ]. More...
 
double[] NextDoubles (int count)
 Array of size count of double precision floating point random numbers in the interval [0, 1]. More...
 
double[] NextDoubles (int count, double maxInclusive)
 Array of size count of double precision floating point random numbers in the interval [0, maxInclusive . More...
 
double[] NextDoubles (int count, double minInclusive, double maxInclusive)
 Array of size count of double precision floating point random numbers in the interval [minInclusive , maxInclusive ]. More...
 
byte NextByte ()
 Random byte. More...
 
byte[] NextBytes (int count)
 Array of size count of random bytes. More...
 
bool NextBool ()
 Random boolean. More...
 
bool[] NextBools (int count)
 Array of size count of random booleans. More...
 
int Equidistribution ()
 Equidistribution this generator. More...
 
int EquidistributionPow2 ()
 Power of two exponent of the equidistribution of this generator. More...
 
int PeriodPow2 ()
 Base 2 exponent of the period of this generator, i.e. Period of Generator = 2^PeriodPow2(). More...
 
void SetStream (int sequence)
 Set the stream for this generator. More...
 
void SetStream (ulong sequence)
 Set the stream for this generator. More...
 
ulong CurrentStream ()
 Query the current stream used by this generator. More...
 
 PcgExtended ()
 Initializes a new instance of the T:Crystal.PcgExtended class. More...
 
 PcgExtended (int seed)
 Initializes a new instance of the T:Crystal.PcgExtended class. More...
 
 PcgExtended (ulong seed)
 Initializes a new instance of the T:Crystal.PcgExtended class. More...
 
 PcgExtended (int seed, int sequence)
 Initializes a new instance of the T:Crystal.PcgExtended class. More...
 
 PcgExtended (ulong seed, ulong sequence)
 Initializes a new instance of the T:Crystal.PcgExtended class. More...
 
 PcgExtended (int seed, int tablePow2, int advancePow2)
 Initializes a new instance of the T:Crystal.PcgExtended class. More...
 
 PcgExtended (ulong seed, int tablePow2, int advancePow2)
 Initializes a new instance of the T:Crystal.PcgExtended class. More...
 
 PcgExtended (int seed, int sequence, int tablePow2, int advancePow2)
 Initializes a new instance of the T:Crystal.PcgExtended class. More...
 
 PcgExtended (ulong seed, ulong sequence, int tablePow2, int advancePow2)
 Initializes a new instance of the T:Crystal.PcgExtended class. More...
 

Properties

static PcgExtended Default [get]
 Default instance. More...
 

Detailed Description

PCG (Permuted Congruential Generator) Extended is a C# port from C++ of a part of the extended PCG family of generators presented in "PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation" by Melissa E. O'Neill. The code follows closely the one made available by O'Neill at her site: http://www.pcg-random.org/using-pcg-cpp.html To understand how exactly this generator works read this: http://www.pcg-random.org/pdf/toms-oneill-pcg-family-v1.02.pdf its a fun read, enjoy! The most important difference between this version and PCG is that the generators produced by this class can have extremely large periods (extremely!) and have configurable k-dimensional equidistribution. All this at a very small speed penalty! (Upto 1024-dimensionally equidistributed generators perform faster than System.Random, at least on the machines I have access to). Fun fact, the period of PCG Extended for _table_mask = 14 is 2^(524352) which is more than 10^(157846). To put this in context, the number particles in the known Universe is about 10^(80 to 81ish) if we also count photons that number goes up (with a lot of effort) to 10^(90ish). Now, there are estimates that say that visible matter (counting photons, energy-matter same thing...) accounts for 5% of the matter in the visible Universe, so if these estimates are correct the total visible+invisible particles/(energy particles) in the visible Universe would approximately be 10^(91). That means that this generator has a period that is 157755 orders of magnitude larger than the number of all particles in the visible Universe... Also, if the universe had an equal number of particles (to the period of PCG 14), that would mean that its mean density (at its current volume) would be so high that the entire Universe would collapse unto its weight into a black hole.

Constructor & Destructor Documentation

Crystal.PcgExtended.PcgExtended ( )
inline

Initializes a new instance of the T:Crystal.PcgExtended class.

Crystal.PcgExtended.PcgExtended ( int  seed)
inline

Initializes a new instance of the T:Crystal.PcgExtended class.

Parameters
seedThe seed.
Crystal.PcgExtended.PcgExtended ( ulong  seed)
inline

Initializes a new instance of the T:Crystal.PcgExtended class.

Parameters
seedThe seed.
Crystal.PcgExtended.PcgExtended ( int  seed,
int  sequence 
)
inline

Initializes a new instance of the T:Crystal.PcgExtended class.

Parameters
seedThe seed.
sequenceThe sequence.
Crystal.PcgExtended.PcgExtended ( ulong  seed,
ulong  sequence 
)
inline

Initializes a new instance of the T:Crystal.PcgExtended class.

Parameters
seedThe seed.
sequenceThe sequence.
Crystal.PcgExtended.PcgExtended ( int  seed,
int  tablePow2,
int  advancePow2 
)
inline

Initializes a new instance of the T:Crystal.PcgExtended class.

Parameters
seedThe seed.
tablePow2The table pow2.
advancePow2The advance pow2.
Crystal.PcgExtended.PcgExtended ( ulong  seed,
int  tablePow2,
int  advancePow2 
)
inline

Initializes a new instance of the T:Crystal.PcgExtended class.

Parameters
seedThe seed.
tablePow2The table pow2.
advancePow2The advance pow2.
Crystal.PcgExtended.PcgExtended ( int  seed,
int  sequence,
int  tablePow2,
int  advancePow2 
)
inline

Initializes a new instance of the T:Crystal.PcgExtended class.

Parameters
seedThe seed.
sequenceThe sequence.
tablePow2The table pow2.
advancePow2The advance pow2.
Crystal.PcgExtended.PcgExtended ( ulong  seed,
ulong  sequence,
int  tablePow2,
int  advancePow2 
)
inline

Initializes a new instance of the T:Crystal.PcgExtended class.

Parameters
seedThe seed.
sequenceThe sequence.
tablePow2The table pow2.
advancePow2The advance pow2.

Member Function Documentation

ulong Crystal.PcgExtended.CurrentStream ( )
inline

Query the current stream used by this generator.

int Crystal.PcgExtended.Equidistribution ( )
inline

Equidistribution this generator.

int Crystal.PcgExtended.EquidistributionPow2 ( )
inline

Power of two exponent of the equidistribution of this generator.

Returns
int Crystal.PcgExtended.Next ( )
inline

Random integer in the interval [0, int.MaxValue].

int Crystal.PcgExtended.Next ( int  maxExclusive)
inline

Random integer in the semi-open interval [0, maxExclusive ).

Parameters
maxExclusiveThe maximum value; exclusive.
Exceptions
T:System.ArgumentExceptionMax Exclusive must be positive
int Crystal.PcgExtended.Next ( int  minInclusive,
int  maxExclusive 
)
inline

Random integer in the interval [minInclusive , maxExclusive ).

Parameters
minInclusiveThe minimum value; inclusive.
maxExclusiveThe maximum value; exclusive.
Exceptions
T:System.ArgumentExceptionMaxExclusive must be larger than MinInclusive
bool Crystal.PcgExtended.NextBool ( )
inline

Random boolean.

bool [] Crystal.PcgExtended.NextBools ( int  count)
inline

Array of size count of random booleans.

Parameters
countThe count.
Exceptions
T:System.ArgumentExceptionZero count
byte Crystal.PcgExtended.NextByte ( )
inline

Random byte.

byte [] Crystal.PcgExtended.NextBytes ( int  count)
inline

Array of size count of random bytes.

Parameters
countThe count.
Exceptions
T:System.ArgumentExceptionZero count
double Crystal.PcgExtended.NextDouble ( )
inline

Random double precision floating point number in the interval [0, 1].

double Crystal.PcgExtended.NextDouble ( double  maxInclusive)
inline

Random double precision floating point number in the interval [0, maxInclusive ].

Parameters
maxInclusiveThe maximum inclusive.
Exceptions
T:System.ArgumentExceptionMax must be larger than 0
double Crystal.PcgExtended.NextDouble ( double  minInclusive,
double  maxInclusive 
)
inline

Random double precision floating point number in the interval [minInclusive , maxInclusive ].

Parameters
minInclusiveThe minimum inclusive.
maxInclusiveThe maximum inclusive.
Exceptions
T:System.ArgumentExceptionMax must be larger than min
double [] Crystal.PcgExtended.NextDoubles ( int  count)
inline

Array of size count of double precision floating point random numbers in the interval [0, 1].

Parameters
countThe count.
Exceptions
T:System.ArgumentExceptionZero count
double [] Crystal.PcgExtended.NextDoubles ( int  count,
double  maxInclusive 
)
inline

Array of size count of double precision floating point random numbers in the interval [0, maxInclusive .

Parameters
countThe count.
maxInclusiveThe maximum inclusive.
Exceptions
T:System.ArgumentExceptionZero count
double [] Crystal.PcgExtended.NextDoubles ( int  count,
double  minInclusive,
double  maxInclusive 
)
inline

Array of size count of double precision floating point random numbers in the interval [minInclusive , maxInclusive ].

Parameters
countThe count.
minInclusiveThe minimum inclusive.
maxInclusiveThe maximum inclusive.
Exceptions
T:System.ArgumentExceptionZero count
float Crystal.PcgExtended.NextFloat ( )
inline

Random single precision floating point number in the interval [0,1].

float Crystal.PcgExtended.NextFloat ( float  maxInclusive)
inline

Random single precision floating point number in the interval [0, maxInclusive ].

Parameters
maxInclusiveThe maximum inclusive.
Exceptions
T:System.ArgumentExceptionMaxInclusive must be larger than 0
float Crystal.PcgExtended.NextFloat ( float  minInclusive,
float  maxInclusive 
)
inline

Random single precision floating point number in the interval [minInclusive , maxInclusive ].

Parameters
minInclusiveThe minimum inclusive.
maxInclusiveThe maximum inclusive.
Exceptions
T:System.ArgumentExceptionMax must be larger than min
float [] Crystal.PcgExtended.NextFloats ( int  count)
inline

Array of size count of single precision floating point random numbers in the interval [0,1].

Parameters
countThe count.
Exceptions
T:System.ArgumentExceptionZero count
float [] Crystal.PcgExtended.NextFloats ( int  count,
float  maxInclusive 
)
inline

Array of size count of single precision floating point random numbers in the interval [0, maxInclusive ].

Parameters
countThe count.
maxInclusiveThe maximum inclusive.
Exceptions
T:System.ArgumentExceptionZero count
float [] Crystal.PcgExtended.NextFloats ( int  count,
float  minInclusive,
float  maxInclusive 
)
inline

Array of size count of single precision floating point random numbers in the interval [minInclusive , maxInclusive ].

Parameters
countThe count.
minInclusiveThe minimum inclusive.
maxInclusiveThe maximum inclusive.
Exceptions
T:System.ArgumentExceptionZero count
int [] Crystal.PcgExtended.NextInts ( int  count)
inline

Array of size count of random integers in the interval [0, int.MaxValue].

Parameters
countThe count.
Exceptions
T:System.ArgumentExceptionZero count
int [] Crystal.PcgExtended.NextInts ( int  count,
int  maxExclusive 
)
inline

Array of size count of random integers in the interval [0, maxExclusive ).

Parameters
countThe count.
maxExclusiveThe maximum value; exclusive.
Exceptions
T:System.ArgumentExceptionZero count
int [] Crystal.PcgExtended.NextInts ( int  count,
int  minInclusive,
int  maxExclusive 
)
inline

Array of size count of random integers in the interval [minInclusive , maxExclusive ).

Parameters
countThe count.
minInclusiveThe minimum value; inclusive.
maxExclusiveThe maximum value; exclusive.
Exceptions
T:System.ArgumentExceptionZero count
uint Crystal.PcgExtended.NextUInt ( )
inline

Random unsigned integer in the interval [0, uint.MaxValue].

uint Crystal.PcgExtended.NextUInt ( uint  maxExclusive)
inline

Random unsigned integer in the interval [0, maxExclusive ).

Parameters
maxExclusiveThe maximum value; exclusive.
uint Crystal.PcgExtended.NextUInt ( uint  minInclusive,
uint  maxExclusive 
)
inline

Random unsigned integer in the interval [minInclusive , maxExclusive ).

Parameters
minInclusiveThe minimum value; inclusive.
maxExclusiveThe maximum value; exclusive.
Exceptions
T:System.ArgumentException
uint [] Crystal.PcgExtended.NextUInts ( int  count)
inline

Array of size count of unsigned integers in the interval [0, uint.MaxValue].

Parameters
countThe count.
Exceptions
T:System.ArgumentExceptionZero count
uint [] Crystal.PcgExtended.NextUInts ( int  count,
uint  maxExclusive 
)
inline

Array of size count of unsigned integers in the interval [0, maxExclusive ).

Parameters
countThe count.
maxExclusiveThe maximum exclusive.
Exceptions
T:System.ArgumentExceptionZero count
uint [] Crystal.PcgExtended.NextUInts ( int  count,
uint  minInclusive,
uint  maxExclusive 
)
inline

Array of size count of unsigned integers in the interval [minInclusive , maxExclusive ).

Parameters
countThe count.
minInclusiveThe minimum inclusive.
maxExclusiveThe maximum exclusive.
Exceptions
T:System.ArgumentExceptionZero count
int Crystal.PcgExtended.PeriodPow2 ( )
inline

Base 2 exponent of the period of this generator, i.e. Period of Generator = 2^PeriodPow2().

void Crystal.PcgExtended.SetStream ( int  sequence)
inline

Set the stream for this generator.

Parameters
sequenceThe sequence.
void Crystal.PcgExtended.SetStream ( ulong  sequence)
inline

Set the stream for this generator.

Parameters
sequenceThe sequence.

Property Documentation

PcgExtended Crystal.PcgExtended.Default
staticget

Default instance.


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