Class RandomExtensions
Provides random data generation.
Inherited Members
Namespace: DotNext
Assembly: DotNext.dll
Syntax
public static class RandomExtensions
Methods
View SourceNext()
Generates non-negative integer.
Declaration
public static int Next()
Returns
| Type | Description |
|---|---|
| int | A 32-bit signed integer that is in range [0, MaxValue). |
NextBoolean(double)
Generates a random boolean value.
Declaration
public static bool NextBoolean(double trueProbability = 0.5)
Parameters
| Type | Name | Description |
|---|---|---|
| double | trueProbability | A probability of true result (should be between 0.0 and 1.0). |
Returns
| Type | Description |
|---|---|
| bool | Randomly generated boolean value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
NextBoolean(Random, double)
Generates a random boolean value.
Declaration
public static bool NextBoolean(this Random random, double trueProbability = 0.5)
Parameters
| Type | Name | Description |
|---|---|---|
| Random | random | |
| double | trueProbability | A probability of true result (should be between 0.0 and 1.0). |
Returns
| Type | Description |
|---|---|
| bool | Randomly generated boolean value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
NextDouble()
Returns a random floating-point number that is in range [0, 1).
Declaration
public static double NextDouble()
Returns
| Type | Description |
|---|---|
| double | Randomly generated floating-point number. |
Next<T>()
Generates a random value of blittable type.
Declaration
public static T Next<T>() where T : unmanaged
Returns
| Type | Description |
|---|---|
| T | The randomly generated value. |
Type Parameters
| Name | Description |
|---|---|
| T | The blittable type. |
Next<T>(Random)
Generates a random value of blittable type.
Declaration
public static T Next<T>(this Random random) where T : unmanaged
Parameters
| Type | Name | Description |
|---|---|---|
| Random | random |
Returns
| Type | Description |
|---|---|
| T | The randomly generated value. |
Type Parameters
| Name | Description |
|---|---|
| T | The blittable type. |
Peek<T>(Random, IReadOnlyCollection<T>)
Gets the random element from the collection.
Declaration
public static T Peek<T>(this Random random, IReadOnlyCollection<T> collection)
Parameters
| Type | Name | Description |
|---|---|---|
| Random | random | |
| IReadOnlyCollection<T> | collection | The collection to get the random element. |
Returns
| Type | Description |
|---|---|
| T | The random element from the collection. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of elements in the collection. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
Peek<T>(Random, ReadOnlySpan<T>)
Chooses the random element in the span.
Declaration
public static T Peek<T>(this Random random, ReadOnlySpan<T> span)
Parameters
| Type | Name | Description |
|---|---|---|
| Random | random | |
| ReadOnlySpan<T> | span | The span of elements. |
Returns
| Type | Description |
|---|---|
| T | Randomly selected element from the span. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of elements in the span. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
Shuffle<T>(Random, IList<T>)
Randomizes elements in the list.
Declaration
public static void Shuffle<T>(this Random random, IList<T> list) where T : notnull
Parameters
| Type | Name | Description |
|---|---|---|
| Random | random | |
| IList<T> | list | The list to shuffle. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of items in the list. |