Table of Contents

Class RandomUtility

Namespace
Uncreated.Warfare.Util
Assembly
Uncreated.Warfare.dll

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

bool

GetDouble()

Thread-safe function to get a random double-precision decimal within the range [0, 1].

public static double GetDouble()

Returns

double

GetDouble(double)

Thread-safe function to get a random double-precision decimal within the range [0, upperInclusive].

public static double GetDouble(double upperInclusive)

Parameters

upperInclusive double

Returns

double

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

lowerInclusive double
upperInclusive double

Returns

double

GetFloat()

Thread-safe function to get a random single-precision decimal within the range [0, 1].

public static float GetFloat()

Returns

float

GetFloat(float)

Thread-safe function to get a random single-precision decimal within the range [0, upperInclusive].

public static float GetFloat(float upperInclusive)

Parameters

upperInclusive float

Returns

float

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

lowerInclusive float
upperInclusive float

Returns

float

GetIndex(ICollection)

Thread-safe function to get a random index within a list.

public static int GetIndex(ICollection list)

Parameters

list ICollection

Returns

int

Exceptions

ArgumentException

list is 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

list IReadOnlyList<T>
weightSelector Func<T, double>

Returns

int

Type Parameters

T

Exceptions

ArgumentException

list is 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

list IReadOnlyList<T>
weightSelector Func<T, float>

Returns

int

Type Parameters

T

Exceptions

ArgumentException

list is empty.

GetInteger()

Thread-safe function to get a random integer within the range [0, MaxValue).

public static int GetInteger()

Returns

int

GetInteger(int)

Thread-safe function to get a random integer within the range [0, upperExclusive).

public static int GetInteger(int upperExclusive)

Parameters

upperExclusive int

Returns

int

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

lowerInclusive int
upperExclusive int

Returns

int

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

list IReadOnlyList<T>
weightSelector Func<T, double>
amount int

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

list IReadOnlyList<T>
weightSelector Func<T, float>
amount int

Returns

T[]

Type Parameters

T