Common
A library of common classes.
RandomSeed Class Reference

A class for performing pseudo-random number generation. More...

Public Member Functions

bool ChanceSatisfied (double chance)
 Draws a random number and returns true if it satisfies the specified probability. More...
 
RandomSeed Copy ()
 Returns a copy of the object. More...
 
double double y DoubleInsideUnitCircle ()
 
int DrawWeightedIndex (IList< double > weights)
 Draws a random weighted index from a list. More...
 
int DrawWeightedIndex (IList< double > weights, List< double > totals)
 Draws a random weighted index from a list. The specified totals buffer allows for minimal garbage generation. More...
 
int DrawWeightedIndex (IList< float > weights)
 Draws a random weighted index from a list. More...
 
int DrawWeightedIndex (IList< float > weights, List< double > totals)
 Draws a random weighted index from a list. The specified totals buffer allows for minimal garbage generation. More...
 
List< int > DrawWeightedIndexes (IList< double > weights, int count, bool withReplacement)
 Draws a quantity of random weighted indexes from a list. Based on the draw weights and whether indexes are drawn with replacement, the resulting list may be less than the specified count. More...
 
List< int > DrawWeightedIndexes (IList< float > weights, int count, bool withReplacement)
 Draws a quantity of random weighted indexes from a list. Based on the draw weights and whether indexes are drawn with replacement, the resulting list may be less than the specified count. More...
 
float float y FloatInsideUnitCircle ()
 
int Next ()
 Returns a random integer on the interval [0, int.MaxValue). More...
 
int Next (int maxValue)
 Returns a random value on the interval [0, maxValue). More...
 
int Next (int minValue, int maxValue)
 Returns a random value on the interval [minValue, maxValue). More...
 
double NextDouble ()
 Returns a random double on the interval [0, 1). More...
 
double NextDouble (double maxValue)
 Returns a random double on the interval [0, maxValue). More...
 
double NextDouble (double minValue, double maxValue)
 Returns a random double on the interval [minValue, maxValue). More...
 
float NextFloat ()
 Returns a random float on the interval [0, 1). More...
 
float NextFloat (float maxValue)
 Returns a random float on the interval [0, maxValue). More...
 
float NextFloat (float minValue, float maxValue)
 Returns a random float on the interval [minValue, maxValue). More...
 
 RandomSeed ()
 Initializes a new random seed based on the current system ticks. More...
 
 RandomSeed (int seed)
 Initializes a new random seed. More...
 
void SetSeed (int seed)
 Sets the random seed and initializes the randomizer. More...
 
void Shuffle< T > (IList< T > list)
 Shuffles the specified list in place. More...
 
List< T > Shuffled< T > (IEnumerable< T > collection)
 Returns a new shuffled copy of the collection. More...
 
override string ToString ()
 

Public Attributes

float x
 Returns a random floating precision point inside the unit circle. More...
 
double x
 Returns a random double precision point inside the unit circle. More...
 

Properties

static RandomSeed Current = new RandomSeed() [get]
 The current global random number generator. More...
 
int Position1 [getset]
 The first position of the randomizer. More...
 
int Position2 [getset]
 The second position of the randomizer. More...
 
int Seed [getprivate set]
 The random seed. More...
 
int[] Seeds = new int[56] [getset]
 An array of previous seeds. More...
 

Private Member Functions

int DrawIndex (IList< double > totals)
 Draws an index from the list of cumulative weights. More...
 
List< int > DrawWeightedIndexesWithoutReplacement (IList< double > weights, int count)
 Draws a quantity of random weighted indexes from a list without replacement. More...
 
List< int > DrawWeightedIndexesWithoutReplacement (IList< float > weights, int count)
 Draws a quantity of random weighted indexes from a list without replacement. More...
 
List< int > DrawWeightedIndexesWithReplacement (IList< double > weights, int count)
 Draws a quantity of random weighted indexes from a list with replacement. More...
 
List< int > DrawWeightedIndexesWithReplacement (IList< float > weights, int count)
 Draws a quantity of random weighted indexes from a list with replacement. More...
 
double NextLargeDouble ()
 Returns a random high resolution double on the interval [0, 1). More...
 
 RandomSeed (RandomSeed other)
 Initializes a copy of a random seed. More...
 

Static Private Member Functions

static int Mod (int value)
 Returns the positive modulo of a value with respect to int.MaxValue. More...
 
static int WrapIndex (int value)
 Wraps an index if it exceeds the top array bounds. More...
 

Detailed Description

A class for performing pseudo-random number generation.

References

Definition at line 18 of file RandomSeed.cs.

Constructor & Destructor Documentation

◆ RandomSeed() [1/3]

Initializes a new random seed based on the current system ticks.

Definition at line 52 of file RandomSeed.cs.

◆ RandomSeed() [2/3]

RandomSeed ( int  seed)

Initializes a new random seed.

Parameters
seedThe random seed.

Definition at line 61 of file RandomSeed.cs.

◆ RandomSeed() [3/3]

RandomSeed ( RandomSeed  other)
private

Initializes a copy of a random seed.

Parameters
otherThe random seed to be copied.

Definition at line 70 of file RandomSeed.cs.

Member Function Documentation

◆ ChanceSatisfied()

bool ChanceSatisfied ( double  chance)

Draws a random number and returns true if it satisfies the specified probability.

Parameters
chanceThe probability, on the interval [0, 1].

Definition at line 524 of file RandomSeed.cs.

◆ Copy()

RandomSeed Copy ( )

Returns a copy of the object.

Definition at line 88 of file RandomSeed.cs.

◆ DoubleInsideUnitCircle()

double double y DoubleInsideUnitCircle ( )

Definition at line 255 of file RandomSeed.cs.

◆ DrawIndex()

int DrawIndex ( IList< double >  totals)
private

Draws an index from the list of cumulative weights.

Parameters
totalsA list of cumulative weights.

Definition at line 308 of file RandomSeed.cs.

◆ DrawWeightedIndex() [1/4]

int DrawWeightedIndex ( IList< double >  weights)

Draws a random weighted index from a list.

Parameters
weightsA list of weights.

Definition at line 328 of file RandomSeed.cs.

◆ DrawWeightedIndex() [2/4]

int DrawWeightedIndex ( IList< double >  weights,
List< double >  totals 
)

Draws a random weighted index from a list. The specified totals buffer allows for minimal garbage generation.

Parameters
weightsA list of weights.
totalsThe totals buffer.

Definition at line 360 of file RandomSeed.cs.

◆ DrawWeightedIndex() [3/4]

int DrawWeightedIndex ( IList< float >  weights)

Draws a random weighted index from a list.

Parameters
weightsA list of weights.

Definition at line 343 of file RandomSeed.cs.

◆ DrawWeightedIndex() [4/4]

int DrawWeightedIndex ( IList< float >  weights,
List< double >  totals 
)

Draws a random weighted index from a list. The specified totals buffer allows for minimal garbage generation.

Parameters
weightsA list of weights.
totalsThe totals buffer.

Definition at line 372 of file RandomSeed.cs.

◆ DrawWeightedIndexes() [1/2]

List< int > DrawWeightedIndexes ( IList< double >  weights,
int  count,
bool  withReplacement 
)

Draws a quantity of random weighted indexes from a list. Based on the draw weights and whether indexes are drawn with replacement, the resulting list may be less than the specified count.

Parameters
weightsA list of index draw weights.
countThe desired number of drawn indexes.
withReplacementIf false, the indexes will be drawn without replacement.

Definition at line 386 of file RandomSeed.cs.

◆ DrawWeightedIndexes() [2/2]

List< int > DrawWeightedIndexes ( IList< float >  weights,
int  count,
bool  withReplacement 
)

Draws a quantity of random weighted indexes from a list. Based on the draw weights and whether indexes are drawn with replacement, the resulting list may be less than the specified count.

Parameters
weightsA list of index draw weights.
countThe desired number of drawn indexes.
withReplacementIf false, the indexes will be drawn without replacement.

Definition at line 457 of file RandomSeed.cs.

◆ DrawWeightedIndexesWithoutReplacement() [1/2]

List< int > DrawWeightedIndexesWithoutReplacement ( IList< double >  weights,
int  count 
)
private

Draws a quantity of random weighted indexes from a list without replacement.

Parameters
weightsA list of index draw weights.
countThe desired number of drawn indexes.

Definition at line 424 of file RandomSeed.cs.

◆ DrawWeightedIndexesWithoutReplacement() [2/2]

List< int > DrawWeightedIndexesWithoutReplacement ( IList< float >  weights,
int  count 
)
private

Draws a quantity of random weighted indexes from a list without replacement.

Parameters
weightsA list of index draw weights.
countThe desired number of drawn indexes.

Definition at line 495 of file RandomSeed.cs.

◆ DrawWeightedIndexesWithReplacement() [1/2]

List< int > DrawWeightedIndexesWithReplacement ( IList< double >  weights,
int  count 
)
private

Draws a quantity of random weighted indexes from a list with replacement.

Parameters
weightsA list of index draw weights.
countThe desired number of drawn indexes.

Definition at line 399 of file RandomSeed.cs.

◆ DrawWeightedIndexesWithReplacement() [2/2]

List< int > DrawWeightedIndexesWithReplacement ( IList< float >  weights,
int  count 
)
private

Draws a quantity of random weighted indexes from a list with replacement.

Parameters
weightsA list of index draw weights.
countThe desired number of drawn indexes.

Definition at line 470 of file RandomSeed.cs.

◆ FloatInsideUnitCircle()

float float y FloatInsideUnitCircle ( )

Definition at line 246 of file RandomSeed.cs.

◆ Mod()

static int Mod ( int  value)
staticprivate

Returns the positive modulo of a value with respect to int.MaxValue.

Parameters
valueThe value.

Definition at line 97 of file RandomSeed.cs.

◆ Next() [1/3]

int Next ( )

Returns a random integer on the interval [0, int.MaxValue).

Returns

Definition at line 152 of file RandomSeed.cs.

◆ Next() [2/3]

int Next ( int  maxValue)

Returns a random value on the interval [0, maxValue).

Parameters
maxValueThe maximum value.

Definition at line 171 of file RandomSeed.cs.

◆ Next() [3/3]

int Next ( int  minValue,
int  maxValue 
)

Returns a random value on the interval [minValue, maxValue).

Parameters
minValueThe minimum value.
maxValueThe maximum value.

Definition at line 181 of file RandomSeed.cs.

◆ NextDouble() [1/3]

double NextDouble ( )

Returns a random double on the interval [0, 1).

Definition at line 218 of file RandomSeed.cs.

◆ NextDouble() [2/3]

double NextDouble ( double  maxValue)

Returns a random double on the interval [0, maxValue).

Parameters
maxValueThe maximum value.

Definition at line 227 of file RandomSeed.cs.

◆ NextDouble() [3/3]

double NextDouble ( double  minValue,
double  maxValue 
)

Returns a random double on the interval [minValue, maxValue).

Parameters
minValueThe minimum value.
maxValueThe maximum value.

Definition at line 237 of file RandomSeed.cs.

◆ NextFloat() [1/3]

float NextFloat ( )

Returns a random float on the interval [0, 1).

Definition at line 191 of file RandomSeed.cs.

◆ NextFloat() [2/3]

float NextFloat ( float  maxValue)

Returns a random float on the interval [0, maxValue).

Parameters
maxValueThe maximum value.

Definition at line 200 of file RandomSeed.cs.

◆ NextFloat() [3/3]

float NextFloat ( float  minValue,
float  maxValue 
)

Returns a random float on the interval [minValue, maxValue).

Parameters
minValueThe minimum value.
maxValueThe maximum value.

Definition at line 210 of file RandomSeed.cs.

◆ NextLargeDouble()

double NextLargeDouble ( )
private

Returns a random high resolution double on the interval [0, 1).

Definition at line 267 of file RandomSeed.cs.

◆ SetSeed()

void SetSeed ( int  seed)

Sets the random seed and initializes the randomizer.

Parameters
seedThe random seed.

Definition at line 119 of file RandomSeed.cs.

◆ Shuffle< T >()

void Shuffle< T > ( IList< T >  list)

Shuffles the specified list in place.

Parameters
listThe list to shuffle.

Definition at line 284 of file RandomSeed.cs.

◆ Shuffled< T >()

List< T > Shuffled< T > ( IEnumerable< T >  collection)

Returns a new shuffled copy of the collection.

Parameters
collectionThe collection

Definition at line 297 of file RandomSeed.cs.

◆ ToString()

override string ToString ( )

Definition at line 80 of file RandomSeed.cs.

◆ WrapIndex()

static int WrapIndex ( int  value)
staticprivate

Wraps an index if it exceeds the top array bounds.

Parameters
valueThe index.

Definition at line 108 of file RandomSeed.cs.

Member Data Documentation

◆ x [1/2]

float x

Returns a random floating precision point inside the unit circle.

Definition at line 246 of file RandomSeed.cs.

◆ x [2/2]

double x

Returns a random double precision point inside the unit circle.

Definition at line 255 of file RandomSeed.cs.

Property Documentation

◆ Current

RandomSeed Current = new RandomSeed()
staticget

The current global random number generator.

Definition at line 23 of file RandomSeed.cs.

◆ Position1

int Position1
getsetprivate

The first position of the randomizer.

Definition at line 35 of file RandomSeed.cs.

◆ Position2

int Position2
getsetprivate

The second position of the randomizer.

Definition at line 41 of file RandomSeed.cs.

◆ Seed

int Seed
getprivate set

The random seed.

Definition at line 29 of file RandomSeed.cs.

◆ Seeds

int [] Seeds = new int[56]
getsetprivate

An array of previous seeds.

Definition at line 47 of file RandomSeed.cs.


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