Show / Hide Table of Contents

Class RandomExtensions

Provides random data generation.

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

Methods

| Improve this Doc View Source

Next(RandomNumberGenerator)

Generates random non-negative random integer.

Declaration
public static int Next(this RandomNumberGenerator random)
Parameters
Type Name Description
RandomNumberGenerator random

The source of random numbers.

Returns
Type Description
Int32

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

| Improve this Doc View Source

Next<T>(Random)

Generates random value of blittable type.

Declaration
public static T Next<T>(this Random random)

    where T : struct
Parameters
Type Name Description
Random random

The source of random numbers.

Returns
Type Description
T

The randomly generated value.

Type Parameters
Name Description
T

The blittable type.

| Improve this Doc View Source

Next<T>(RandomNumberGenerator)

Generates random value of blittable type.

Declaration
public static T Next<T>(this RandomNumberGenerator random)

    where T : struct
Parameters
Type Name Description
RandomNumberGenerator random

The source of random numbers.

Returns
Type Description
T

The randomly generated value.

Type Parameters
Name Description
T

The blittable type.

| Improve this Doc View Source

NextBoolean(Random, Double)

Generates random boolean value.

Declaration
public static bool NextBoolean(this Random random, double trueProbability = 0.5)
Parameters
Type Name Description
Random random

The source of random numbers.

Double trueProbability

A probability of true result (should be between 0.0 and 1.0).

Returns
Type Description
Boolean

Randomly generated boolean value.

Exceptions
Type Condition
ArgumentOutOfRangeException

trueProbability value is invalid.

| Improve this Doc View Source

NextBoolean(RandomNumberGenerator, Double)

Generates random boolean value.

Declaration
public static bool NextBoolean(this RandomNumberGenerator random, double trueProbability = 0.5)
Parameters
Type Name Description
RandomNumberGenerator random

The source of random numbers.

Double trueProbability

A probability of true result (should be between 0.0 and 1.0).

Returns
Type Description
Boolean

Randomly generated boolean value.

Exceptions
Type Condition
ArgumentOutOfRangeException

trueProbability value is invalid.

| Improve this Doc View Source

NextDouble(RandomNumberGenerator)

Returns a random floating-point number that is in range [0, 1).

Declaration
public static double NextDouble(this RandomNumberGenerator random)
Parameters
Type Name Description
RandomNumberGenerator random

The source of random numbers.

Returns
Type Description
Double

Randomly generated floating-point number.

| Improve this Doc View Source

NextString(Random, Char[], Int32)

Generates random string of the given length.

Declaration
public static string NextString(this Random random, char[] allowedChars, int length)
Parameters
Type Name Description
Random random

The source of random numbers.

Char[] allowedChars

The array of allowed characters for the random string.

Int32 length

The length of the random string.

Returns
Type Description
String

Randomly generated string.

Exceptions
Type Condition
ArgumentOutOfRangeException

length is less than zero.

| Improve this Doc View Source

NextString(Random, ReadOnlySpan<Char>, Int32)

Generates random string of the given length.

Declaration
public static string NextString(this Random random, ReadOnlySpan<char> allowedChars, int length)
Parameters
Type Name Description
Random random

The source of random numbers.

ReadOnlySpan<Char> allowedChars

The allowed characters for the random string.

Int32 length

The length of the random string.

Returns
Type Description
String

Randomly generated string.

Exceptions
Type Condition
ArgumentOutOfRangeException

length is less than zero.

| Improve this Doc View Source

NextString(Random, String, Int32)

Generates random string of the given length.

Declaration
public static string NextString(this Random random, string allowedChars, int length)
Parameters
Type Name Description
Random random

The source of random numbers.

String allowedChars

The string of allowed characters for the random string.

Int32 length

The length of the random string.

Returns
Type Description
String

Randomly generated string.

Exceptions
Type Condition
ArgumentOutOfRangeException

length is less than zero.

| Improve this Doc View Source

NextString(RandomNumberGenerator, Char[], Int32)

Generates random string of the given length.

Declaration
public static string NextString(this RandomNumberGenerator random, char[] allowedChars, int length)
Parameters
Type Name Description
RandomNumberGenerator random

The source of random numbers.

Char[] allowedChars

The array of allowed characters for the random string.

Int32 length

The length of the random string.

Returns
Type Description
String

Randomly generated string.

Exceptions
Type Condition
ArgumentOutOfRangeException

length is less than zero.

| Improve this Doc View Source

NextString(RandomNumberGenerator, ReadOnlySpan<Char>, Int32)

Generates random string of the given length.

Declaration
public static string NextString(this RandomNumberGenerator random, ReadOnlySpan<char> allowedChars, int length)
Parameters
Type Name Description
RandomNumberGenerator random

The source of random numbers.

ReadOnlySpan<Char> allowedChars

The allowed characters for the random string.

Int32 length

The length of the random string.

Returns
Type Description
String

Randomly generated string.

Exceptions
Type Condition
ArgumentOutOfRangeException

length is less than zero.

| Improve this Doc View Source

NextString(RandomNumberGenerator, String, Int32)

Generates random string of the given length.

Declaration
public static string NextString(this RandomNumberGenerator random, string allowedChars, int length)
Parameters
Type Name Description
RandomNumberGenerator random

The source of random numbers.

String allowedChars

The string of allowed characters for the random string.

Int32 length

The length of the random string.

Returns
Type Description
String

Randomly generated string.

Exceptions
Type Condition
ArgumentOutOfRangeException

length is less than zero.

  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX