Class RandomExtensions
A set of extensions for dealing with Random
public static class RandomExtensions
- Inheritance
-
RandomExtensions
- Inherited Members
Methods
GetRandomEntry<T>(Random, ICollection<T>)
Gets a random entry from the given collection with uniform chance.
public static T GetRandomEntry<T>(this Random random, ICollection<T> entries)
Parameters
randomRandomThe random
entriesICollection<T>The entries to choose from
Returns
- T
A random entry
Type Parameters
TThe entries' type
GetRandomWeightedEntry<T>(Random, ICollection<T>, Func<T, int>)
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>(this Random random, ICollection<T> entries, Func<T, int> weightFunc)
Parameters
randomRandomThe random
entriesICollection<T>The entries to choose from
weightFuncFunc<T, int>A function that applies weight to each entry
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>(Random, ICollection<T>, Func<T, float>)
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>(this Random random, ICollection<T> entries, Func<T, float> weightFunc)
Parameters
randomRandomThe random
entriesICollection<T>The entries to choose from
weightFuncFunc<T, float>A function that applies weight to each entry
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
NextSingle(Random, float)
Returns a random floating-point number that is greater than or equal to 0, and less than maxValue.
public static float NextSingle(this Random random, float maxValue)
Parameters
Returns
- float
A single-precision floating point number that is greater than or equal to 0, and less than
maxValue.
NextSingle(Random, float, float)
Returns a random floating-point number that is greater than or equal to minValue, and less than maxValue.
public static float NextSingle(this Random random, float minValue, float maxValue)
Parameters
randomRandomThe random.
minValuefloatThe (inclusive) minimum value.
maxValuefloatThe (exclusive) maximum value.
Returns
- float
A single-precision floating point number that is greater than or equal to
minValue, and less thanmaxValue.