Class IListExtensions
- Namespace
- FishMMO.Shared
- Assembly
- FishMMO-SharedUtility.dll
Extension methods for IList, providing high-performance randomization and shuffling utilities. Utilizes Thread-Local Storage (TLS) to ensure high concurrency without lock contention.
public static class IListExtensions
- Inheritance
-
IListExtensions
- Inherited Members
Methods
GetRandom<T>(IList<T>?)
Returns a random element from the list without modifying the collection.
public static T? GetRandom<T>(this IList<T>? list)
Parameters
listIList<T>The list to select from.
Returns
- T
A random element, or default(T) if the list is null or empty.
Type Parameters
TThe type of elements in the list.
Shuffle<T>(IList<T>?)
Shuffles the elements of the list in place using the Fisher-Yates algorithm. This ensures a mathematically uniform distribution (O(n) complexity).
public static void Shuffle<T>(this IList<T>? list)
Parameters
listIList<T>The list to be shuffled.
Type Parameters
TThe type of elements in the list.
TakeRandom<T>(IList<T>?)
Selects a random element and removes it from the list in a single operation. Useful for unique loot drops or exhausting a deck of cards.
public static T? TakeRandom<T>(this IList<T>? list)
Parameters
listIList<T>The list to modify.
Returns
- T
The removed random element, or default(T) if the list is null or empty.
Type Parameters
TThe type of elements in the list.