Method Random
View SourceRandom()
Returns an infinite sequence of random integers using the standard .NET random number generator.
Declaration
public static IAsyncEnumerable<int> Random()
Returns
Type | Description |
---|---|
IAsyncEnumerable<int> | An infinite sequence of random integers |
Remarks
The implementation internally uses a shared, thread-local instance of Random to generate a random number on each iteration. The actual Random instance used therefore will depend on the thread on which a single iteration is taking place; that is the call to MoveNext(). If the overall iteration takes place on different threads (e.g. via asynchronous awaits completing on different threads) then various different Random instances will be involved in the generation of the sequence of random numbers. Because the Random instance is shared, if multiple sequences are generated on the same thread, the order of enumeration affects the resulting sequences.
Random(Random)
Returns an infinite sequence of random integers using the supplied random number generator.
Declaration
public static IAsyncEnumerable<int> Random(Random rand)
Parameters
Type | Name | Description |
---|---|---|
Random | rand | Random generator used to produce random numbers |
Returns
Type | Description |
---|---|
IAsyncEnumerable<int> | An infinite sequence of random integers |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
Random(int)
Returns an infinite sequence of random integers between zero and a given maximum.
Declaration
public static IAsyncEnumerable<int> Random(int maxValue)
Parameters
Type | Name | Description |
---|---|---|
int | maxValue | exclusive upper bound for the random values returned |
Returns
Type | Description |
---|---|
IAsyncEnumerable<int> | An infinite sequence of random integers |
Remarks
The implementation internally uses a shared, thread-local instance of Random to generate a random number on each iteration. The actual Random instance used therefore will depend on the thread on which a single iteration is taking place; that is the call to MoveNext(). If the overall iteration takes place on different threads (e.g. via asynchronous awaits completing on different threads) then various different Random instances will be involved in the generation of the sequence of random numbers. Because the Random instance is shared, if multiple sequences are generated on the same thread, the order of enumeration affects the resulting sequences.
Random(Random, int)
Returns an infinite sequence of random integers between zero and a given maximum using the supplied random number generator.
Declaration
public static IAsyncEnumerable<int> Random(Random rand, int maxValue)
Parameters
Type | Name | Description |
---|---|---|
Random | rand | Random generator used to produce values |
int | maxValue | Exclusive upper bound for random values returned |
Returns
Type | Description |
---|---|
IAsyncEnumerable<int> | An infinite sequence of random integers |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
Random(int, int)
Returns an infinite sequence of random integers between a given minimum and a maximum.
Declaration
public static IAsyncEnumerable<int> Random(int minValue, int maxValue)
Parameters
Type | Name | Description |
---|---|---|
int | minValue | Inclusive lower bound of the values returned |
int | maxValue | Exclusive upper bound of the values returned |
Returns
Type | Description |
---|---|
IAsyncEnumerable<int> | An infinite sequence of random integers |
Remarks
The implementation internally uses a shared, thread-local instance of Random to generate a random number on each iteration. The actual Random instance used therefore will depend on the thread on which a single iteration is taking place; that is the call to MoveNext(). If the overall iteration takes place on different threads (e.g. via asynchronous awaits completing on different threads) then various different Random instances will be involved in the generation of the sequence of random numbers. Because the Random instance is shared, if multiple sequences are generated on the same thread, the order of enumeration affects the resulting sequences.
Random(Random, int, int)
Returns an infinite sequence of random integers between a given minumum and a maximum using the supplied random number generator.
Declaration
public static IAsyncEnumerable<int> Random(Random rand, int minValue, int maxValue)
Parameters
Type | Name | Description |
---|---|---|
Random | rand | Generator used to produce random numbers |
int | minValue | Inclusive lower bound of the values returned |
int | maxValue | Exclusive upper bound of the values returned |
Returns
Type | Description |
---|---|
IAsyncEnumerable<int> | An infinite sequence of random integers |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
ArgumentOutOfRangeException | Thrown if |