![]() |
Common
A library of common classes.
|
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... | |
A class for performing pseudo-random number generation.
Definition at line 18 of file RandomSeed.cs.
RandomSeed | ( | ) |
Initializes a new random seed based on the current system ticks.
Definition at line 52 of file RandomSeed.cs.
RandomSeed | ( | int | seed | ) |
Initializes a new random seed.
seed | The random seed. |
Definition at line 61 of file RandomSeed.cs.
|
private |
Initializes a copy of a random seed.
other | The random seed to be copied. |
Definition at line 70 of file RandomSeed.cs.
bool ChanceSatisfied | ( | double | chance | ) |
Draws a random number and returns true if it satisfies the specified probability.
chance | The probability, on the interval [0, 1]. |
Definition at line 524 of file RandomSeed.cs.
RandomSeed Copy | ( | ) |
Returns a copy of the object.
Definition at line 88 of file RandomSeed.cs.
double double y DoubleInsideUnitCircle | ( | ) |
Definition at line 255 of file RandomSeed.cs.
|
private |
Draws an index from the list of cumulative weights.
totals | A list of cumulative weights. |
Definition at line 308 of file RandomSeed.cs.
int DrawWeightedIndex | ( | IList< double > | weights | ) |
Draws a random weighted index from a list.
weights | A list of weights. |
Definition at line 328 of file RandomSeed.cs.
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.
weights | A list of weights. |
totals | The totals buffer. |
Definition at line 360 of file RandomSeed.cs.
int DrawWeightedIndex | ( | IList< float > | weights | ) |
Draws a random weighted index from a list.
weights | A list of weights. |
Definition at line 343 of file RandomSeed.cs.
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.
weights | A list of weights. |
totals | The totals buffer. |
Definition at line 372 of file RandomSeed.cs.
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.
weights | A list of index draw weights. |
count | The desired number of drawn indexes. |
withReplacement | If false, the indexes will be drawn without replacement. |
Definition at line 386 of file RandomSeed.cs.
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.
weights | A list of index draw weights. |
count | The desired number of drawn indexes. |
withReplacement | If false, the indexes will be drawn without replacement. |
Definition at line 457 of file RandomSeed.cs.
|
private |
Draws a quantity of random weighted indexes from a list without replacement.
weights | A list of index draw weights. |
count | The desired number of drawn indexes. |
Definition at line 424 of file RandomSeed.cs.
|
private |
Draws a quantity of random weighted indexes from a list without replacement.
weights | A list of index draw weights. |
count | The desired number of drawn indexes. |
Definition at line 495 of file RandomSeed.cs.
|
private |
Draws a quantity of random weighted indexes from a list with replacement.
weights | A list of index draw weights. |
count | The desired number of drawn indexes. |
Definition at line 399 of file RandomSeed.cs.
|
private |
Draws a quantity of random weighted indexes from a list with replacement.
weights | A list of index draw weights. |
count | The desired number of drawn indexes. |
Definition at line 470 of file RandomSeed.cs.
float float y FloatInsideUnitCircle | ( | ) |
Definition at line 246 of file RandomSeed.cs.
|
staticprivate |
Returns the positive modulo of a value with respect to int.MaxValue.
value | The value. |
Definition at line 97 of file RandomSeed.cs.
int Next | ( | ) |
Returns a random integer on the interval [0, int.MaxValue).
Definition at line 152 of file RandomSeed.cs.
int Next | ( | int | maxValue | ) |
Returns a random value on the interval [0, maxValue).
maxValue | The maximum value. |
Definition at line 171 of file RandomSeed.cs.
int Next | ( | int | minValue, |
int | maxValue | ||
) |
Returns a random value on the interval [minValue, maxValue).
minValue | The minimum value. |
maxValue | The maximum value. |
Definition at line 181 of file RandomSeed.cs.
double NextDouble | ( | ) |
Returns a random double on the interval [0, 1).
Definition at line 218 of file RandomSeed.cs.
double NextDouble | ( | double | maxValue | ) |
Returns a random double on the interval [0, maxValue).
maxValue | The maximum value. |
Definition at line 227 of file RandomSeed.cs.
double NextDouble | ( | double | minValue, |
double | maxValue | ||
) |
Returns a random double on the interval [minValue, maxValue).
minValue | The minimum value. |
maxValue | The maximum value. |
Definition at line 237 of file RandomSeed.cs.
float NextFloat | ( | ) |
Returns a random float on the interval [0, 1).
Definition at line 191 of file RandomSeed.cs.
float NextFloat | ( | float | maxValue | ) |
Returns a random float on the interval [0, maxValue).
maxValue | The maximum value. |
Definition at line 200 of file RandomSeed.cs.
float NextFloat | ( | float | minValue, |
float | maxValue | ||
) |
Returns a random float on the interval [minValue, maxValue).
minValue | The minimum value. |
maxValue | The maximum value. |
Definition at line 210 of file RandomSeed.cs.
|
private |
Returns a random high resolution double on the interval [0, 1).
Definition at line 267 of file RandomSeed.cs.
void SetSeed | ( | int | seed | ) |
Sets the random seed and initializes the randomizer.
seed | The random seed. |
Definition at line 119 of file RandomSeed.cs.
void Shuffle< T > | ( | IList< T > | list | ) |
Shuffles the specified list in place.
list | The list to shuffle. |
Definition at line 284 of file RandomSeed.cs.
List< T > Shuffled< T > | ( | IEnumerable< T > | collection | ) |
Returns a new shuffled copy of the collection.
collection | The collection |
Definition at line 297 of file RandomSeed.cs.
override string ToString | ( | ) |
Definition at line 80 of file RandomSeed.cs.
|
staticprivate |
Wraps an index if it exceeds the top array bounds.
value | The index. |
Definition at line 108 of file RandomSeed.cs.
float x |
Returns a random floating precision point inside the unit circle.
Definition at line 246 of file RandomSeed.cs.
double x |
Returns a random double precision point inside the unit circle.
Definition at line 255 of file RandomSeed.cs.
|
staticget |
The current global random number generator.
Definition at line 23 of file RandomSeed.cs.
|
getsetprivate |
The first position of the randomizer.
Definition at line 35 of file RandomSeed.cs.
|
getsetprivate |
The second position of the randomizer.
Definition at line 41 of file RandomSeed.cs.
|
getprivate set |
The random seed.
Definition at line 29 of file RandomSeed.cs.
|
getsetprivate |
An array of previous seeds.
Definition at line 47 of file RandomSeed.cs.