This commit is contained in:
@@ -46,6 +46,8 @@ public interface IRandom
|
||||
/// Get a random boolean. 50% chance of being true.
|
||||
/// </summary>
|
||||
public bool GetBool();
|
||||
|
||||
public T OneOf<T>(IReadOnlyList<T> list);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -94,4 +96,12 @@ public class RandomImpl : IRandom
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool GetBool() => _random.Next(2) == 1;
|
||||
|
||||
/// <inheritdoc />
|
||||
public T OneOf<T>(IReadOnlyList<T> list)
|
||||
{
|
||||
if (list.Count == 0)
|
||||
throw new ArgumentException("List cannot be empty.", nameof(list));
|
||||
return list[GetInt(list.Count)];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user