Table of Contents

Class RandomExtensions

Namespace
MLEM.Maths
Assembly
MLEM.dll

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 Random

The 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 Random

The 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 Random

The 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 Random

The 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

random Random

The random.

maxValue float

The (exclusive) maximum value.

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 Random

The random.

minValue float

The (inclusive) minimum value.

maxValue float

The (exclusive) maximum value.

Returns

float

A single-precision floating point number that is greater than or equal to minValue, and less than maxValue.