Table of Contents

Class RandomUtils

Namespace
S1API.Utils
Assembly
S1API.dll

A utility class providing random selection functionality for lists and numeric ranges. This class is intended for public use by mod developers.

public static class RandomUtils
Inheritance
RandomUtils
Inherited Members

Methods

PickMany<T>(IList<T>, int)

Returns a specified number of unique random elements from a list. If the count exceeds the number of available elements, returns all elements in random order.

public static List<T> PickMany<T>(this IList<T> list, int count)

Parameters

list IList<T>

The list of items to pick from.

count int

The number of random items to pick.

Returns

List<T>

A list containing the selected random items, or an empty list if the input list is null or empty.

Type Parameters

T

PickOne<T>(IList<T>)

Returns a random element from the provided list, or the default value of type T if the list is null or empty.

public static T PickOne<T>(this IList<T> list)

Parameters

list IList<T>

The list from which to select a random element.

Returns

T

A randomly selected element from the list, or the default value of type T if the list is null or empty.

Type Parameters

T

PickUnique<T>(IList<T>, Func<T, bool>, int)

Returns a random element from a list that satisfies the given condition, with a maximum number of attempts. If no such element can be found within the allowed attempts, returns the default value of the type.

public static T PickUnique<T>(this IList<T> list, Func<T, bool> isDuplicate, int maxTries = 10)

Parameters

list IList<T>

The list of items to pick from.

isDuplicate Func<T, bool>

A function to determine if the selected item satisfies the duplicate condition.

maxTries int

The maximum number of attempts to find a valid item.

Returns

T

A randomly selected item that satisfies the condition, or the default value of the type if no valid item is found.

Type Parameters

T

RangeInt(int, int)

Generates a random integer within the specified range.

public static int RangeInt(int minInclusive, int maxExclusive)

Parameters

minInclusive int

The inclusive lower bound of the random number.

maxExclusive int

The exclusive upper bound of the random number.

Returns

int

A random integer greater than or equal to minInclusive and less than maxExclusive.