Skip to content

OnixLabs.Core.RandomExtensions

Matthew Layton edited this page Nov 15, 2026 · 2 revisions

RandomExtensions Class

Extension methods for Random instances.

Namespace OnixLabs.Core
Assembly OnixLabs.Core.dll (NuGet)
Inheritance object → RandomExtensions

Definition

[EditorBrowsable(EditorBrowsableState.Never)]
public static class RandomExtensions

Note This class is decorated with [EditorBrowsable(EditorBrowsableState.Never)], which keeps the container class itself out of IntelliSense lists while its extension methods remain fully usable on the receiver types. Bring the methods into scope with using OnixLabs.Core;.

Remarks

RandomExtensions augments System.Random with collection-aware helpers. The Next<T> overload selects a uniformly distributed element from any IReadOnlyList<T>, complementing the BCL's built-in numeric Next methods.

Methods

Method Returns Description
Next<T>(IReadOnlyList<T>) T Obtains a random element from the specified read-only list.

Next<T>(IReadOnlyList<T>)

public T Next<T>(IReadOnlyList<T> items)

Obtains a random element from the specified IReadOnlyList<T> items, selecting a uniformly distributed index in the range [0, items.Count).

Parameter Type Description
items IReadOnlyList<T> The items from which to obtain a random element.

Returns — A random element from the specified items.

string[] colors = ["Red", "Green", "Blue"];
string picked = Random.Shared.Next(colors);

See Also

ONIXLabs .NET Library


Clone this wiki locally