Show / Hide Table of Contents

Class GoRogueEnhancedRandomExtensions

Class containing some extension methods for ShaiRandom.Generators.IEnhancedRandom instances.

Inheritance
object
GoRogueEnhancedRandomExtensions
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: ShaiRandom.Generators
Assembly: GoRogue.dll
Syntax
public static class GoRogueEnhancedRandomExtensions

Methods

View Source

PercentageCheck(IEnhancedRandom, float)

Performs a percentage check that has the specified chance to succeed. The percentage should be in range [0, 100] (inclusive).

Declaration
public static bool PercentageCheck(this IEnhancedRandom rng, float percentage)
Parameters
Type Name Description
IEnhancedRandom rng
float percentage

Percentage chance (out of 100) that this check will succeed. Must be in range [0, 100].

Returns
Type Description
bool
View Source

RandomElement(IEnhancedRandom, IReadOnlyArea)

Extension method that selects and returns a random position from the Area, using the rng specified. An exception is thrown if the area is empty.

Declaration
public static Point RandomElement(this IEnhancedRandom rng, IReadOnlyArea area)
Parameters
Type Name Description
IEnhancedRandom rng
IReadOnlyArea area

The area to select from. Must be non-empty.

Returns
Type Description
Point

Item selected.

Exceptions
Type Condition
ArgumentException

An empty Area was provided.

View Source

RandomElement(IEnhancedRandom, IReadOnlyArea, Func<Point, bool>)

Extension method that selects and returns a random position from the given (non-empty) IReadOnlyArea for which the selector function given returns true, using the rng specified. Items are repeatedly selected until a qualifying index is found.

Declaration
public static Point RandomElement(this IEnhancedRandom rng, IReadOnlyArea area, Func<Point, bool> selector)
Parameters
Type Name Description
IEnhancedRandom rng
IReadOnlyArea area

The area to select from. Must be non-empty.

Func<Point, bool> selector

Function that should return true if the given index is valid selection, false otherwise.

Returns
Type Description
Point

Item selected.

Remarks

This function will never return if no positions in the area return true for the given selector, and could take a very long time to execute if the area is large and the selector returns true for very few of its positions. For a more reliable termination, use the overload taking a maxTries parameter instead: RandomElement(IEnhancedRandom, IReadOnlyArea, Func<Point, bool>, int)

Exceptions
Type Condition
ArgumentException

An empty Area was provided.

View Source

RandomElement(IEnhancedRandom, IReadOnlyArea, Func<Point, bool>, int)

Extension method that selects and returns a random position from the given (non-empty) IReadOnlyArea for which the selector function given returns true, using the rng specified. Items are repeatedly selected until a qualifying index is found, or the specified maxTries value is reached.

Declaration
public static Point RandomElement(this IEnhancedRandom rng, IReadOnlyArea area, Func<Point, bool> selector, int maxTries)
Parameters
Type Name Description
IEnhancedRandom rng
IReadOnlyArea area

The area to select from. Must be non-empty.

Func<Point, bool> selector

Function that should return true if the given index is valid selection, false otherwise.

int maxTries

Maximum number of selections to make before giving up and throwing an exception.

Returns
Type Description
Point

Position selected.

Exceptions
Type Condition
ArgumentException

An empty Area was provided.

ArgumentOutOfRangeException

A maxTries value that was less than or equal to 0 was provided.

MaxAttemptsReachedException

A value was selected maxTries times, and none of the selections returned true from selector

View Source

RandomElement<T>(IEnhancedRandom, IGridView<T>)

Gets the value at a random position in the IGridView, using the rng given.

Declaration
public static T RandomElement<T>(this IEnhancedRandom rng, IGridView<T> gridView)
Parameters
Type Name Description
IEnhancedRandom rng
IGridView<T> gridView

The grid view to select from.

Returns
Type Description
T

The item at a random position in the IGridView.

Type Parameters
Name Description
T
View Source

RandomElement<T>(IEnhancedRandom, IGridView<T>, Func<Point, T, bool>)

Extension method that selects and returns a random item from the given (non-empty) IGridView<T> for which the selector function given returns true, using the rng specified. Items are repeatedly selected until a qualifying value is found.

Declaration
public static T RandomElement<T>(this IEnhancedRandom rng, IGridView<T> gridView, Func<Point, T, bool> selector)
Parameters
Type Name Description
IEnhancedRandom rng
IGridView<T> gridView

The grid view to select from.

Func<Point, T, bool> selector

Function that takes a position, and the value at that position, and returns true if it is an acceptable selection, and false if not.

Returns
Type Description
T

The item at the first random position in the IGridView selected for which the selector returns true.

Type Parameters
Name Description
T
Remarks

This function will never return if no positions in the view return true for the given selector, and could take a very long time to execute if the view is large and the selector returns true for very few of its positions. For a more reliable termination, use the overload taking a maxTries parameter instead.

Exceptions
Type Condition
ArgumentException

An empty grid view was provided.

View Source

RandomElement<T>(IEnhancedRandom, IGridView<T>, Func<Point, T, bool>, int)

Extension method that selects and returns a random item from the given (non-empty) IGridView<T> for which the selector function given returns true, using the rng specified. Items are repeatedly selected until a qualifying value is found, or the specified maxTries value is reached.

Declaration
public static T RandomElement<T>(this IEnhancedRandom rng, IGridView<T> gridView, Func<Point, T, bool> selector, int maxTries)
Parameters
Type Name Description
IEnhancedRandom rng
IGridView<T> gridView

The grid view to select from.

Func<Point, T, bool> selector

Function that takes a position, and the value at that position, and returns true if it is an acceptable selection, and false if not.

int maxTries

Maximum number of selections to make before giving up and throwing an exception.

Returns
Type Description
T

The item at the first random position in the IGridView selected for which the selector returns true.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentException

An empty grid view was provided.

ArgumentOutOfRangeException

A maxTries value that was less than or equal to 0 was provided.

MaxAttemptsReachedException

A value was selected maxTries times, and none of the selections returned true from selector

View Source

RandomIndex(IEnhancedRandom, IReadOnlyArea)

Extension method that selects and returns a random valid index of a position in a (non-empty) Area.

Declaration
public static int RandomIndex(this IEnhancedRandom rng, IReadOnlyArea area)
Parameters
Type Name Description
IEnhancedRandom rng
IReadOnlyArea area

The area to select from. Must be non-empty.

Returns
Type Description
int

The index selected.

Exceptions
Type Condition
ArgumentException

An empty Area was provided.

View Source

RandomIndex(IEnhancedRandom, IReadOnlyArea, Func<int, bool>)

Extension method that selects and returns a random valid index for some position in the (non-empty) IReadOnlyArea for which the selector function given returns true, using the rng specified. Indices are repeatedly selected until a qualifying index is found.

Declaration
public static int RandomIndex(this IEnhancedRandom rng, IReadOnlyArea area, Func<int, bool> selector)
Parameters
Type Name Description
IEnhancedRandom rng
IReadOnlyArea area

The area to select from. Must be non-empty.

Func<int, bool> selector

Function that should return true if the given index is valid selection, false otherwise.

Returns
Type Description
int

Index selected.

Remarks

This function will never return if no indices in the area return true for the given selector, and could take a very long time to execute if the area is large and the selector returns true for very few of those indices. For a more reliable termination, use the overload taking a maxTries parameter instead: RandomIndex(IEnhancedRandom, IReadOnlyArea, Func<int, bool>, int)

Exceptions
Type Condition
ArgumentException

An empty Area was provided.

View Source

RandomIndex(IEnhancedRandom, IReadOnlyArea, Func<int, bool>, int)

Extension method that selects and returns a random valid index for some position in the (non-empty) IReadOnlyArea for which the selector function given returns true, using the rng specified. Indices are repeatedly selected until a qualifying index is found, or the specified maxTries value is reached.

Declaration
public static int RandomIndex(this IEnhancedRandom rng, IReadOnlyArea area, Func<int, bool> selector, int maxTries)
Parameters
Type Name Description
IEnhancedRandom rng
IReadOnlyArea area

The area to select from. Must be non-empty.

Func<int, bool> selector

Function that should return true if the given index is valid selection, false otherwise.

int maxTries

Maximum number of selections to make before giving up and throwing an exception.

Returns
Type Description
int

Index selected.

Exceptions
Type Condition
ArgumentException

An empty Area was provided.

ArgumentOutOfRangeException

A maxTries value that was less than or equal to 0 was provided.

MaxAttemptsReachedException

A value was selected maxTries times, and none of the selections returned true from selector

View Source

RandomPosition(IEnhancedRandom, Rectangle)

Randomly selects a position within the Rectangle.

Declaration
public static Point RandomPosition(this IEnhancedRandom rng, Rectangle rect)
Parameters
Type Name Description
IEnhancedRandom rng
Rectangle rect

Rectangle to select a position from.

Returns
Type Description
Point

A random position within the Rectangle.

View Source

RandomPosition(IEnhancedRandom, Rectangle, Func<Point, bool>)

Gets a random position in the rectangle, for which the selector returns true. Random positions will continuously be generated until one that qualifies is found.

Declaration
public static Point RandomPosition(this IEnhancedRandom rng, Rectangle rect, Func<Point, bool> selector)
Parameters
Type Name Description
IEnhancedRandom rng
Rectangle rect

The Rectangle to select from.

Func<Point, bool> selector

Function that takes a position, and returns true if it is an acceptable selection, and false if not.

Returns
Type Description
Point

A random position in the Rectangle for which the selector returns true.

Remarks

This function will never return if no positions in the rectangle return true for the given selector, and could take a very long time to execute if the rectangle is large and the selector returns true for very few of its positions. For a more reliable termination, use the overload taking a maxTries parameter instead.

Exceptions
Type Condition
ArgumentException

An empty rectangle was given.

View Source

RandomPosition(IEnhancedRandom, Rectangle, Func<Point, bool>, int)

Gets a random position in the rectangle, for which the selector returns true. Random positions will continuously be generated until one that qualifies is found, or maxTries selections occur.

Declaration
public static Point RandomPosition(this IEnhancedRandom rng, Rectangle rect, Func<Point, bool> selector, int maxTries)
Parameters
Type Name Description
IEnhancedRandom rng
Rectangle rect

The Rectangle to select from.

Func<Point, bool> selector

Function that takes a position, and returns true if it is an acceptable selection, and false if not.

int maxTries

Maximum number of selections to make before giving up and throwing an exception.

Returns
Type Description
Point

A random position in the Rectangle for which the selector returns true.

Exceptions
Type Condition
ArgumentException

An empty rectangle was provided.

ArgumentOutOfRangeException

A maxTries value that was less than or equal to 0 was provided.

MaxAttemptsReachedException

A value was selected maxTries times, and none of the selected positions returned true from selector.

View Source

RandomPosition<T>(IEnhancedRandom, IGridView<T>)

Randomly selects a position within the IGridView.

Declaration
public static Point RandomPosition<T>(this IEnhancedRandom rng, IGridView<T> gridView)
Parameters
Type Name Description
IEnhancedRandom rng
IGridView<T> gridView

Grid view to select a position from.

Returns
Type Description
Point

A random position within the IGridView.

Type Parameters
Name Description
T
View Source

RandomPosition<T>(IEnhancedRandom, IGridView<T>, HashSet<T>)

Extension method that selects and returns a random position from the given (non-empty) IGridView<T> whose value in that grid view is is one of the ones in the specified hash set. Random positions are repeatedly selected until one that has one of the specified values is found.

Declaration
public static Point RandomPosition<T>(this IEnhancedRandom rng, IGridView<T> gridView, HashSet<T> validValues)
Parameters
Type Name Description
IEnhancedRandom rng
IGridView<T> gridView

The grid view to select from.

HashSet<T> validValues

A set of values to look for in the IGridView to determine whether or not a generated position is valid.

Returns
Type Description
Point

A random position whose value in this IGridView is equal to one of the values specified.

Type Parameters
Name Description
T
Remarks

This function will never return if no positions in the view have one of the values given, and could take a very long time to execute if the view is large and very few of its positions have one of the specified values. For a more reliable termination, use the overload taking a maxTries parameter instead.

Exceptions
Type Condition
ArgumentException

An empty grid view was provided.

View Source

RandomPosition<T>(IEnhancedRandom, IGridView<T>, HashSet<T>, int)

Extension method that selects and returns a random position from the given (non-empty) IGridView<T> whose value in that grid view is is one of the ones in the specified hash set. Positions are repeatedly selected until one that has one of the specified values is found, or the specified maxTries value is reached.

Declaration
public static Point RandomPosition<T>(this IEnhancedRandom rng, IGridView<T> gridView, HashSet<T> validValues, int maxTries)
Parameters
Type Name Description
IEnhancedRandom rng
IGridView<T> gridView

The grid view to select from.

HashSet<T> validValues

A set of values to look for in the IGridView to determine whether or not a generated position is valid.

int maxTries

Maximum number of selections to make before giving up and throwing an exception.

Returns
Type Description
Point

A random position whose value in this IGridView is equal to one of the values specified.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentException

An empty grid view was provided.

ArgumentOutOfRangeException

A maxTries value that was less than or equal to 0 was provided.

MaxAttemptsReachedException

A value was selected maxTries times, and none of the selected positions had one of the given values.

View Source

RandomPosition<T>(IEnhancedRandom, IGridView<T>, IEnumerable<T>)

Extension method that selects and returns a random position from the given (non-empty) IGridView<T> whose value in that grid view is is one of the ones specified. Random positions are repeatedly selected until one that has one of the specified values is found.

Declaration
public static Point RandomPosition<T>(this IEnhancedRandom rng, IGridView<T> gridView, IEnumerable<T> validValues)
Parameters
Type Name Description
IEnhancedRandom rng
IGridView<T> gridView

The grid view to select from.

IEnumerable<T> validValues

A set of values to look for in the IGridView to determine whether or not a generated position is valid.

Returns
Type Description
Point

A random position whose value in this IGridView is equal to one of the values specified.

Type Parameters
Name Description
T
Remarks

This function will never return if no positions in the view have one of the values given, and could take a very long time to execute if the view is large and very few of its positions have one of the specified values. For a more reliable termination, use the overload taking a maxTries parameter instead.

Exceptions
Type Condition
ArgumentException

An empty grid view was provided.

View Source

RandomPosition<T>(IEnhancedRandom, IGridView<T>, IEnumerable<T>, int)

Extension method that selects and returns a random position from the given (non-empty) IGridView<T> whose value in that grid view is is one of the ones specified. Positions are repeatedly selected until one that has one of the specified values is found, or the specified maxTries value is reached.

Declaration
public static Point RandomPosition<T>(this IEnhancedRandom rng, IGridView<T> gridView, IEnumerable<T> validValues, int maxTries)
Parameters
Type Name Description
IEnhancedRandom rng
IGridView<T> gridView

The grid view to select from.

IEnumerable<T> validValues

A set of values to look for in the IGridView to determine whether or not a generated position is valid.

int maxTries

Maximum number of selections to make before giving up and throwing an exception.

Returns
Type Description
Point

A random position whose value in this IGridView is equal to one of the values specified.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentException

An empty grid view was provided.

ArgumentOutOfRangeException

A maxTries value that was less than or equal to 0 was provided.

MaxAttemptsReachedException

A value was selected maxTries times, and none of the selected positions had one of the given values.

View Source

RandomPosition<T>(IEnhancedRandom, IGridView<T>, Func<Point, T, bool>)

Gets a random position in the grid view, for which the selector returns true. Random positions will continuously be generated until one that qualifies is found.

Declaration
public static Point RandomPosition<T>(this IEnhancedRandom rng, IGridView<T> gridView, Func<Point, T, bool> selector)
Parameters
Type Name Description
IEnhancedRandom rng
IGridView<T> gridView

The grid view to select from.

Func<Point, T, bool> selector

Function that takes a position and the value at that position, and returns true if it is an acceptable selection, and false if not.

Returns
Type Description
Point

A random position in the IGridView for which the selector returns true.

Type Parameters
Name Description
T
Remarks

This function will never return if no positions in the view return true for the given selector, and could take a very long time to execute if the view is large and the selector returns true for very few of its positions. For a more reliable termination, use the overload taking a maxTries parameter instead.

Exceptions
Type Condition
ArgumentException

An empty grid view was given.

View Source

RandomPosition<T>(IEnhancedRandom, IGridView<T>, Func<Point, T, bool>, int)

Gets a random position in the grid view, for which the selector returns true. Random positions will continuously be generated until one that qualifies is found, or maxTries selections occur.

Declaration
public static Point RandomPosition<T>(this IEnhancedRandom rng, IGridView<T> gridView, Func<Point, T, bool> selector, int maxTries)
Parameters
Type Name Description
IEnhancedRandom rng
IGridView<T> gridView

The grid view to select from.

Func<Point, T, bool> selector

Function that takes a position and the value at that position, and returns true if it is an acceptable selection, and false if not.

int maxTries

Maximum number of selections to make before giving up and throwing an exception.

Returns
Type Description
Point

A random position in the IGridView for which the selector returns true.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentException

An empty grid view was provided.

ArgumentOutOfRangeException

A maxTries value that was less than or equal to 0 was provided.

MaxAttemptsReachedException

A value was selected maxTries times, and none of the selected positions returned true from selector.

View Source

RandomPosition<T>(IEnhancedRandom, IGridView<T>, int, params T[])

Extension method that selects and returns a random position from the given (non-empty) IGridView<T> whose value in that grid view is is one of the ones specified. Positions are repeatedly selected until one that has one of the specified values is found, or the specified maxTries value is reached.

Declaration
public static Point RandomPosition<T>(this IEnhancedRandom rng, IGridView<T> gridView, int maxTries, params T[] validValues)
Parameters
Type Name Description
IEnhancedRandom rng
IGridView<T> gridView

The grid view to select from.

int maxTries

Maximum number of selections to make before giving up and throwing an exception.

T[] validValues

A set of values to look for in the IGridView to determine whether or not a generated position is valid.

Returns
Type Description
Point

A random position whose value in this IGridView is equal to one of the values specified.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentException

An empty grid view was provided.

ArgumentOutOfRangeException

A maxTries value that was less than or equal to 0 was provided.

MaxAttemptsReachedException

A value was selected maxTries times, and none of the selected positions had one of the given values.

View Source

RandomPosition<T>(IEnhancedRandom, IGridView<T>, T)

Extension method that selects and returns a random position from the given (non-empty) IGridView<T> whose value in that grid view is the one that is specified. Positions are repeatedly selected until one with the specified value is found.

Declaration
public static Point RandomPosition<T>(this IEnhancedRandom rng, IGridView<T> gridView, T validValue)
Parameters
Type Name Description
IEnhancedRandom rng
IGridView<T> gridView

The grid view to select from.

T validValue

A value to look for in the IGridView to determine whether or not a generated position is valid.

Returns
Type Description
Point

A random position whose value in the current IGridView is equal to the one specified.

Type Parameters
Name Description
T
Remarks

This function will never return if no positions in the view have the value given, and could take a very long time to execute if the view is large and very few of its positions have the specified value. For a more reliable termination, use the overload taking a maxTries parameter instead.

Exceptions
Type Condition
ArgumentException

An empty grid view was provided.

View Source

RandomPosition<T>(IEnhancedRandom, IGridView<T>, T, int)

Extension method that selects and returns a random position from the given (non-empty) IGridView<T> whose value in that grid view is the one that is specified. Positions are repeatedly selected until one with the specified value is found, or the specified maxTries value is reached.

Declaration
public static Point RandomPosition<T>(this IEnhancedRandom rng, IGridView<T> gridView, T validValue, int maxTries)
Parameters
Type Name Description
IEnhancedRandom rng
IGridView<T> gridView

The grid view to select from.

T validValue

A value to look for in the IGridView to determine whether or not a generated position is valid.

int maxTries

Maximum number of selections to make before giving up and throwing an exception.

Returns
Type Description
Point

A random position whose value in the current IGridView is equal to the one specified.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentException

An empty grid view was provided.

ArgumentOutOfRangeException

A maxTries value that was less than or equal to 0 was provided.

MaxAttemptsReachedException

A value was selected maxTries times, and none of the selected positions had a value of validValue.

View Source

RandomPosition<T>(IEnhancedRandom, IGridView<T>, params T[])

Extension method that selects and returns a random position from the given (non-empty) IGridView<T> whose value in that grid view is is one of the ones specified. Random positions are repeatedly selected until one that has one of the specified values is found.

Declaration
public static Point RandomPosition<T>(this IEnhancedRandom rng, IGridView<T> gridView, params T[] validValues)
Parameters
Type Name Description
IEnhancedRandom rng
IGridView<T> gridView

The grid view to select from.

T[] validValues

A set of values to look for in the IGridView to determine whether or not a generated position is valid.

Returns
Type Description
Point

A random position whose value in this IGridView is equal to one of the values specified.

Type Parameters
Name Description
T
Remarks

This function will never return if no positions in the view have one of the values given, and could take a very long time to execute if the view is large and very few of its positions have one of the specified values. For a more reliable termination, use the overload taking a maxTries parameter instead.

Exceptions
Type Condition
ArgumentException

An empty grid view was provided.

  • View Source
In this article
Back to top Generated by DocFX