Table of Contents

Class SingleRandom

Namespace
MLEM.Maths
Assembly
MLEM.dll

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 are tested to be sufficiently "random", that is, to be sufficiently distributed throughout their range, as well as sufficiently different for neighboring seeds.

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

entries ICollection<T>

The entries to choose from

source SeedSource

The SeedSource to use.

Returns

T

A random entry

Type Parameters

T

The 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

entries ICollection<T>

The entries to choose from

weightFunc Func<T, int>

A function that applies weight to each entry

source SeedSource

The SeedSource to use.

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>(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

entries ICollection<T>

The entries to choose from

weightFunc Func<T, float>

A function that applies weight to each entry

source SeedSource

The SeedSource to use.

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

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

source SeedSource

The 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

seed int

The 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

maxValue int

The (exclusive) maximum value.

source SeedSource

The 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

maxValue int

The (exclusive) maximum value.

seed int

The seed to use.

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

minValue int

The (inclusive) minimum value.

maxValue int

The (exclusive) maximum value.

source SeedSource

The 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

minValue int

The (inclusive) minimum value.

maxValue int

The (exclusive) maximum value.

seed int

The 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

source SeedSource

The 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

seed int

The 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

maxValue float

The (exclusive) maximum value.

source SeedSource

The 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

maxValue float

The (exclusive) maximum value.

seed int

The seed to use.

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

minValue float

The (inclusive) minimum value.

maxValue float

The (exclusive) maximum value.

source SeedSource

The 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

minValue float

The (inclusive) minimum value.

maxValue float

The (exclusive) maximum value.

seed int

The seed to use.

Returns

float

The generated number.