Class SingleRandom
The SingleRandom class allows generating single, one-off pseudorandom numbers based on a seed or a SeedSource. The types of numbers that can be generated are int and float, both of which can be generated with specific minimum and maximum values if desired. Methods in this class rely on SeedSource for pseudorandom number generation, which is a linear congruential generator (LCG).
public class SingleRandom
- Inheritance
-
SingleRandom
- Inherited Members
Methods
GetRandomEntry<T>(ICollection<T>, SeedSource)
Gets a random entry from the given collection with uniform chance.
public static T GetRandomEntry<T>(ICollection<T> entries, SeedSource source)
Parameters
entriesICollection<T>The entries to choose from
sourceSeedSourceThe SeedSource to use.
Returns
- T
A random entry
Type Parameters
TThe entries' type
GetRandomWeightedEntry<T>(ICollection<T>, Func<T, int>, SeedSource)
Returns a random entry from the given collection based on the specified weight function. A higher weight for an entry increases its likeliness of being picked.
public static T GetRandomWeightedEntry<T>(ICollection<T> entries, Func<T, int> weightFunc, SeedSource source)
Parameters
entriesICollection<T>The entries to choose from
weightFuncFunc<T, int>A function that applies weight to each entry
sourceSeedSourceThe SeedSource to use.
Returns
- T
A random entry, based on the entries' weight
Type Parameters
TThe entries' type
Exceptions
- IndexOutOfRangeException
If the weight function returns different weights for the same entry
GetRandomWeightedEntry<T>(ICollection<T>, Func<T, float>, SeedSource)
Returns a random entry from the given collection based on the specified weight function. A higher weight for an entry increases its likeliness of being picked.
public static T GetRandomWeightedEntry<T>(ICollection<T> entries, Func<T, float> weightFunc, SeedSource source)
Parameters
entriesICollection<T>The entries to choose from
weightFuncFunc<T, float>A function that applies weight to each entry
sourceSeedSourceThe SeedSource to use.
Returns
- T
A random entry, based on the entries' weight
Type Parameters
TThe entries' type
Exceptions
- IndexOutOfRangeException
If the weight function returns different weights for the same entry
Int(SeedSource)
Generates a single, one-off pseudorandom integer between 0 and MaxValue based on a given source.
This method is guaranteed to return the same result for the same source.
public static int Int(SeedSource source)
Parameters
sourceSeedSourceThe SeedSource to use.
Returns
- int
The generated number.
Int(int)
Generates a single, one-off pseudorandom integer between 0 and MaxValue based on a given seed.
This method is guaranteed to return the same result for the same seed.
public static int Int(int seed)
Parameters
seedintThe seed to use.
Returns
- int
The generated number.
Int(int, SeedSource)
Generates a single, one-off pseudorandom integer between 0 and maxValue based on a given source.
This method is guaranteed to return the same result for the same source.
public static int Int(int maxValue, SeedSource source)
Parameters
maxValueintThe (exclusive) maximum value.
sourceSeedSourceThe SeedSource to use.
Returns
- int
The generated number.
Int(int, int)
Generates a single, one-off pseudorandom integer between 0 and maxValue based on a given seed.
This method is guaranteed to return the same result for the same seed.
public static int Int(int maxValue, int seed)
Parameters
Returns
- int
The generated number.
Int(int, int, SeedSource)
Generates a single, one-off pseudorandom integer between minValue and maxValue based on a given source.
This method is guaranteed to return the same result for the same source.
public static int Int(int minValue, int maxValue, SeedSource source)
Parameters
minValueintThe (inclusive) minimum value.
maxValueintThe (exclusive) maximum value.
sourceSeedSourceThe SeedSource to use.
Returns
- int
The generated number.
Int(int, int, int)
Generates a single, one-off pseudorandom integer between minValue and maxValue based on a given seed.
This method is guaranteed to return the same result for the same seed.
public static int Int(int minValue, int maxValue, int seed)
Parameters
minValueintThe (inclusive) minimum value.
maxValueintThe (exclusive) maximum value.
seedintThe seed to use.
Returns
- int
The generated number.
Single(SeedSource)
Generates a single, one-off pseudorandom floating point number between 0 and 1 based on a given source.
This method is guaranteed to return the same result for the same source.
public static float Single(SeedSource source)
Parameters
sourceSeedSourceThe SeedSource to use.
Returns
- float
The generated number.
Single(int)
Generates a single, one-off pseudorandom floating point number between 0 and 1 based on a given seed.
This method is guaranteed to return the same result for the same seed.
public static float Single(int seed)
Parameters
seedintThe seed to use.
Returns
- float
The generated number.
Single(float, SeedSource)
Generates a single, one-off pseudorandom floating point number between 0 and maxValue based on a given source.
This method is guaranteed to return the same result for the same source.
public static float Single(float maxValue, SeedSource source)
Parameters
maxValuefloatThe (exclusive) maximum value.
sourceSeedSourceThe SeedSource to use.
Returns
- float
The generated number.
Single(float, int)
Generates a single, one-off pseudorandom floating point number between 0 and maxValue based on a given seed.
This method is guaranteed to return the same result for the same seed.
public static float Single(float maxValue, int seed)
Parameters
Returns
- float
The generated number.
Single(float, float, SeedSource)
Generates a single, one-off pseudorandom floating point number between minValue and maxValue based on a given source.
This method is guaranteed to return the same result for the same source.
public static float Single(float minValue, float maxValue, SeedSource source)
Parameters
minValuefloatThe (inclusive) minimum value.
maxValuefloatThe (exclusive) maximum value.
sourceSeedSourceThe SeedSource to use.
Returns
- float
The generated number.
Single(float, float, int)
Generates a single, one-off pseudorandom floating point number between minValue and maxValue based on a given seed.
This method is guaranteed to return the same result for the same seed.
public static float Single(float minValue, float maxValue, int seed)
Parameters
minValuefloatThe (inclusive) minimum value.
maxValuefloatThe (exclusive) maximum value.
seedintThe seed to use.
Returns
- float
The generated number.