M&B: Bannerlord 1.0.0
The horns sound, the ravens gather.
Loading...
Searching...
No Matches
TaleWorlds.Core.MBFastRandom Class Reference

Faster pseudo-random generator based on xor-shift having the same interface as System.Random Adapted from "A fast equivalent for System.Random" by colgreen. Link: https://www.codeproject.com/Articles/9187/A-fast-equivalent-for-System-Random Based on a simple and fast xor-shift pseudo random number generator specified in: Marsaglia, George. (2003). Xorshift RNGs. http://www.jstatsoft.org/v08/i14/xorshift.pdf REMARK_ATES: This version is simplified and a bit improved for performance. Also added random float computation

Public Member Functions

 MBFastRandom ()
 Initialises a new fast random generator using environment tick count as seed More...
 
 MBFastRandom (uint seed1, uint seed2=DefaultSeedY, uint seed3=DefaultSeedZ, uint seed4=DefaultSeedW)
 Initialises a new fast random generator using an int value as seed. More...
 
int Next ()
 Returns a non-negative random integer. More...
 
int Next (int maxValue)
 Returns a non-negative random integer that is less than the specified maximum. More...
 
int Next (int minValue, int maxValue)
 Returns a random integer that is within a specified range. More...
 
double NextDouble ()
 Returns a random double that is greater than or equal to 0.0, and less than 1.0. More...
 
float NextFloat ()
 Returns a random float that is greater than or equal to 0.0, and less than 1.0. More...
 
void NextBytes (byte[] buffer)
 Fills the elements of a specified array of bytes with random numbers. More...
 

Constructor & Destructor Documentation

◆ MBFastRandom() [1/2]

TaleWorlds.Core.MBFastRandom.MBFastRandom ( )

◆ MBFastRandom() [2/2]

TaleWorlds.Core.MBFastRandom.MBFastRandom ( uint  seed1,
uint  seed2 = DefaultSeedY,
uint  seed3 = DefaultSeedZ,
uint  seed4 = DefaultSeedW 
)

Member Function Documentation

◆ Next() [1/3]

int TaleWorlds.Core.MBFastRandom.Next ( )

◆ Next() [2/3]

int TaleWorlds.Core.MBFastRandom.Next ( int  maxValue)
Parameters
maxValueThe exclusive upper bound of the random number to be generated. maxValue must be greater than or equal to 0.

◆ Next() [3/3]

int TaleWorlds.Core.MBFastRandom.Next ( int  minValue,
int  maxValue 
)
Parameters
minValueThe inclusive lower bound of the random number returned.
maxValueThe exclusive upper bound of the random number returned. maxValue must be greater than or equal to minValue.

◆ NextDouble()

double TaleWorlds.Core.MBFastRandom.NextDouble ( )

◆ NextFloat()

float TaleWorlds.Core.MBFastRandom.NextFloat ( )

◆ NextBytes()

void TaleWorlds.Core.MBFastRandom.NextBytes ( byte[]  buffer)
Parameters
bufferThe array to be filled with random numbers.