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
random
RandomThe random
entries
ICollection<T>The entries to choose from
Returns
- T
A random entry
Type Parameters
T
The 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
random
RandomThe random
entries
ICollection<T>The entries to choose from
weightFunc
Func<T, int>A function that applies weight to each entry
Returns
- T
A random entry, based on the entries' weight
Type Parameters
T
The 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
random
RandomThe random
entries
ICollection<T>The entries to choose from
weightFunc
Func<T, float>A function that applies weight to each entry
Returns
- T
A random entry, based on the entries' weight
Type Parameters
T
The entries' type
Exceptions
- IndexOutOfRangeException
If the weight function returns different weights for the same entry
NextSingle(Random)
Returns a random floating-point number that is greater than or equal to 0, and less than 1.
public static float NextSingle(this Random random)
Parameters
random
RandomThe random.
Returns
- float
A single-precision floating point number that is greater than or equal to 0, and less than 1.
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
random
RandomThe random.
minValue
floatThe (inclusive) minimum value.
maxValue
floatThe (exclusive) maximum value.
Returns
- float
A single-precision floating point number that is greater than or equal to
minValue
, and less thanmaxValue
.