Class RandomExtensions
Extension methods for
Inheritance
Namespace: X10D.Core
Assembly: X10D.dll
Syntax
public static class RandomExtensions : object
Methods
| Improve this Doc View SourceNext<T>(Random)
Returns a random value that defined in a specified enum.
Declaration
public static T Next<T>(this Random random)
where T : struct, Enum
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
Returns
Type | Description |
---|---|
T | A |
Type Parameters
Name | Description |
---|---|
T | An enum type. |
NextBoolean(Random)
Returns either true or false based on the next generation of the current
Declaration
public static bool NextBoolean(this Random random)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
Returns
Type | Description |
---|---|
System.Boolean | true if the return value from |
NextByte(Random)
Returns a non-negative random integer.
Declaration
public static byte NextByte(this Random random)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
Returns
Type | Description |
---|---|
System.Byte | An 8-bit unsigned integer that is greater than or equal to 0, and less than |
NextByte(Random, Byte)
Returns a non-negative random integer.
Declaration
public static byte NextByte(this Random random, byte maxValue)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
System.Byte | maxValue | The exclusive upper bound of the random number to be generated. |
Returns
Type | Description |
---|---|
System.Byte | An 8-bit unsigned integer that is greater than or equal to 0, and less than |
NextByte(Random, Byte, Byte)
Returns a non-negative random integer.
Declaration
public static byte NextByte(this Random random, byte minValue, byte maxValue)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
System.Byte | minValue | The inclusive lower bound of the random number to be generated. |
System.Byte | maxValue | The exclusive upper bound of the random number to be generated. |
Returns
Type | Description |
---|---|
System.Byte | An 8-bit unsigned integer greater than or equal to |
NextDouble(Random, Double)
Returns a non-negative random double-precision floating point number that is less than the specified maximum.
Declaration
public static double NextDouble(this Random random, double maxValue)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
System.Double | maxValue | The exclusive upper bound of the random number returned. This value must be greater than or equal to 0. |
Returns
Type | Description |
---|---|
System.Double | A random double-precision floating point number that is greater than or equal to 0, and less than
|
NextDouble(Random, Double, Double)
Returns a random double-precision floating point number that is within a specified range.
Declaration
public static double NextDouble(this Random random, double minValue, double maxValue)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
System.Double | minValue | The inclusive lower bound of the random number returned. |
System.Double | maxValue | The exclusive upper bound of the random number returned. This value must be greater than or equal to
|
Returns
Type | Description |
---|---|
System.Double | A random double-precision floating point number between |
NextFrom<T>(Random, IEnumerable<T>)
Returns a random element from source
using the
Declaration
public static T NextFrom<T>(this Random random, IEnumerable<T> source)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
IEnumerable<T> | source | The source collection from which to draw. |
Returns
Type | Description |
---|---|
T | A random element of type |
Type Parameters
Name | Description |
---|---|
T | The element type. |
Examples
var list = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var random = new Random();
var number = random.NextFrom(list);
|
Improve this Doc
View Source
NextFrom<T>(Random, ReadOnlySpan<T>)
Returns a random element from the specified readonly span of elements using the current
Declaration
public static T NextFrom<T>(this Random random, ReadOnlySpan<T> source)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
ReadOnlySpan<T> | source | The readonly span of elements from which to draw. |
Returns
Type | Description |
---|---|
T | A random element of type |
Type Parameters
Name | Description |
---|---|
T | The element type. |
Examples
Span<int> span = stackalloc span[5];
// populate the span ...
var random = new Random();
var number = random.NextFrom(span.AsReadOnly());
|
Improve this Doc
View Source
NextFrom<T>(Random, Span<T>)
Returns a random element from the specified span of elements using the current
Declaration
public static T NextFrom<T>(this Random random, Span<T> source)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
Span<T> | source | The span of elements from which to draw. |
Returns
Type | Description |
---|---|
T | A random element of type |
Type Parameters
Name | Description |
---|---|
T | The element type. |
Examples
Span<int> span = stackalloc span[5];
// populate the span ...
var random = new Random();
var number = random.NextFrom(span);
|
Improve this Doc
View Source
NextInt16(Random)
Returns a non-negative random integer.
Declaration
public static short NextInt16(this Random random)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
Returns
Type | Description |
---|---|
System.Int16 | An 16-bit signed integer that is greater than or equal to 0, and less than |
NextInt16(Random, Int16)
Returns a non-negative random integer that is less than the specified maximum.
Declaration
public static short NextInt16(this Random random, short maxValue)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
System.Int16 | maxValue | The exclusive upper bound of the random number to be generated. |
Returns
Type | Description |
---|---|
System.Int16 | A 16-bit signed integer that is greater than or equal to 0, and less than |
NextInt16(Random, Int16, Int16)
Returns a random integer that is within a specified range.
Declaration
public static short NextInt16(this Random random, short minValue, short maxValue)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
System.Int16 | minValue | The inclusive lower bound of the random number to be generated. |
System.Int16 | maxValue | The exclusive upper bound of the random number to be generated. |
Returns
Type | Description |
---|---|
System.Int16 | An 8-bit unsigned integer greater than or equal to |
NextSingle(Random)
Returns a random floating-point number that is greater than or equal to 0.0, and less than 1.0.
Declaration
public static float NextSingle(this Random random)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
Returns
Type | Description |
---|---|
System.Single | A single-precision floating point number that is greater than or equal to 0.0, and less than 1.0. |
NextSingle(Random, Single)
Returns a non-negative random single-precision floating point number that is less than the specified maximum.
Declaration
public static float NextSingle(this Random random, float maxValue)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
System.Single | maxValue | The exclusive upper bound of the random number returned. This value must be greater than or equal to 0. |
Returns
Type | Description |
---|---|
System.Single | A random single-precision floating point number that is greater than or equal to 0, and less than
|
NextSingle(Random, Single, Single)
Returns a random single-precision floating point number that is within a specified range.
Declaration
public static float NextSingle(this Random random, float minValue, float maxValue)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
System.Single | minValue | The inclusive lower bound of the random number returned. |
System.Single | maxValue | The exclusive upper bound of the random number returned. This value must be greater than or equal to
|
Returns
Type | Description |
---|---|
System.Single | A random single-precision floating point number between |
NextString(Random, IReadOnlyList<Char>, Int32)
Returns a new string of a specified length which is composed of specified characters.
Declaration
public static string NextString(this Random random, IReadOnlyList<char> source, int length)
Parameters
Type | Name | Description |
---|---|---|
Random | random | The |
IReadOnlyList<System.Char> | source | The source collection of characters to poll. |
System.Int32 | length | The length of the new string to generate. |
Returns
Type | Description |
---|---|
System.String | A |