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
sourceIEnumerable<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
TThe 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
sourceIEnumerable<T>The enumerable to pick from.
Returns
- T
A random element from the enumerable.
Type Parameters
TThe 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
sourceIEnumerable<T>The enumerable to pick from.
countintThe 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
TThe type of the items in the enumerable.