Show / Hide Table of Contents

Class RandomExtensions

Provides random data generation.

Inheritance
object
RandomExtensions
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: DotNext
Assembly: DotNext.dll
Syntax
public static class RandomExtensions

Methods

View Source

Next()

Generates non-negative integer.

Declaration
public static int Next()
Returns
Type Description
int

A 32-bit signed integer that is in range [0, MaxValue).

View Source

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

trueProbability value is invalid.

View Source

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

trueProbability value is invalid.

View Source

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.

View Source

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.

View Source

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.

View Source

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

collection is empty.

View Source

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

span is empty.

View Source

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.

  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾