Class RandomUtility
Thread-safe wrapper utilities for Random.
public static class RandomUtility
- Inheritance
-
RandomUtility
- Inherited Members
Methods
GetBoolean()
Get a random true or false boolean.
public static bool GetBoolean()
Returns
GetDouble()
Thread-safe function to get a random double-precision decimal within the range [0, 1].
public static double GetDouble()
Returns
GetDouble(double)
Thread-safe function to get a random double-precision decimal within the range [0, upperInclusive].
public static double GetDouble(double upperInclusive)
Parameters
upperInclusivedouble
Returns
GetDouble(double, double)
Thread-safe function to get a random double-precision decimal within the range [lowerInclusive, upperInclusive].
public static double GetDouble(double lowerInclusive, double upperInclusive)
Parameters
Returns
GetFloat()
Thread-safe function to get a random single-precision decimal within the range [0, 1].
public static float GetFloat()
Returns
GetFloat(float)
Thread-safe function to get a random single-precision decimal within the range [0, upperInclusive].
public static float GetFloat(float upperInclusive)
Parameters
upperInclusivefloat
Returns
GetFloat(float, float)
Thread-safe function to get a random single-precision decimal within the range [lowerInclusive, upperInclusive].
public static float GetFloat(float lowerInclusive, float upperInclusive)
Parameters
Returns
GetIndex(ICollection)
Thread-safe function to get a random index within a list.
public static int GetIndex(ICollection list)
Parameters
listICollection
Returns
Exceptions
- ArgumentException
listis empty.
GetIndex<T>(IReadOnlyList<T>, Func<T, double>)
Thread-safe function to get a random index within a list given a weight for each element.
public static int GetIndex<T>(IReadOnlyList<T> list, Func<T, double> weightSelector)
Parameters
listIReadOnlyList<T>weightSelectorFunc<T, double>
Returns
Type Parameters
T
Exceptions
- ArgumentException
listis empty.
GetIndex<T>(IReadOnlyList<T>, Func<T, float>)
Thread-safe function to get a random index within a list given a weight for each element.
public static int GetIndex<T>(IReadOnlyList<T> list, Func<T, float> weightSelector)
Parameters
listIReadOnlyList<T>weightSelectorFunc<T, float>
Returns
Type Parameters
T
Exceptions
- ArgumentException
listis empty.
GetInteger()
Thread-safe function to get a random integer within the range [0, MaxValue).
public static int GetInteger()
Returns
GetInteger(int)
Thread-safe function to get a random integer within the range [0, upperExclusive).
public static int GetInteger(int upperExclusive)
Parameters
upperExclusiveint
Returns
GetInteger(int, int)
Thread-safe function to get a random integer within the range [lowerInclusive, upperExclusive).
public static int GetInteger(int lowerInclusive, int upperExclusive)
Parameters
Returns
GetRandomValues<T>(IReadOnlyList<T>, Func<T, double>, int)
Thread-safe function to get a set number of random values with no repeats from list. If more than are in list are requested, less will be returned.
public static T[] GetRandomValues<T>(IReadOnlyList<T> list, Func<T, double> weightSelector, int amount)
Parameters
listIReadOnlyList<T>weightSelectorFunc<T, double>amountint
Returns
- T[]
Type Parameters
T
GetRandomValues<T>(IReadOnlyList<T>, Func<T, float>, int)
Thread-safe function to get a set number of random values with no repeats from list. If more than are in list are requested, less will be returned.
public static T[] GetRandomValues<T>(IReadOnlyList<T> list, Func<T, float> weightSelector, int amount)
Parameters
listIReadOnlyList<T>weightSelectorFunc<T, float>amountint
Returns
- T[]
Type Parameters
T