Table of Contents

Class RandomExtensions

Namespace
Olve.Utilities.CollectionExtensions
Assembly
Olve.Utilities.dll

Provides extension methods for Random.

public static class RandomExtensions
Inheritance
RandomExtensions
Inherited Members

Methods

PickRandomOrDefault<T>(IEnumerable<T>)

Picks a random element from the enumerable or returns the default value if the enumerable is empty.

public static T? PickRandomOrDefault<T>(this IEnumerable<T> source)

Parameters

source IEnumerable<T>

The enumerable to pick from.

Returns

T

A random element from the enumerable or the default value if the enumerable is empty.

Type Parameters

T

The type of the items in the enumerable.

PickRandom<T>(IEnumerable<T>)

Picks a random element from the enumerable.

public static T PickRandom<T>(this IEnumerable<T> source)

Parameters

source IEnumerable<T>

The enumerable to pick from.

Returns

T

A random element from the enumerable.

Type Parameters

T

The type of the items in the enumerable.

PickRandom<T>(IEnumerable<T>, int)

Picks a random element from the enumerable or returns the specified default value if the enumerable is empty.

public static IEnumerable<T> PickRandom<T>(this IEnumerable<T> source, int count)

Parameters

source IEnumerable<T>

The enumerable to pick from.

count int

The number of elements to pick.

Returns

IEnumerable<T>

A random element from the enumerable or the default value if the enumerable is empty.

Type Parameters

T

The type of the items in the enumerable.