Table of Contents

Class RandomUtils

Namespace
Ddth.Utilities
Assembly
Ddth.Utilities.dll

Utility class to generate random values using cryptographically strong value generator RandomNumberGenerator.

public static class RandomUtils
Inheritance
RandomUtils
Inherited Members

Examples

using Ddth.Utilities;

// Generate a random int in range [0, 100)
var randomInt = RandomUtils.Next(0, 100);

// Generate a random char from the set "abc"
var randomChar = RandomUtils.Next("abc");

Methods

Next(short, short)

Generates a random short.

public static short Next(short minValue, short maxValue)

Parameters

minValue short

minimum value to generate (inclusive).

maxValue short

maximum value to generate (exclusive).

Returns

short

The random short in range [minValue, maxValue).

Remarks

minValue must be less than or equal to maxValue.

Exceptions

ArgumentOutOfRangeException

If minValue is greater than maxValue.

Next(int, int)

Generates a random int.

public static int Next(int minValue, int maxValue)

Parameters

minValue int

minimum value to generate (inclusive).

maxValue int

maximum value to generate (exclusive).

Returns

int

The random int in range [minValue, maxValue).

Remarks

minValue must be less than or equal to maxValue.

Exceptions

ArgumentOutOfRangeException

If minValue is greater than maxValue.

Next(long, long)

Generates a random long.

public static long Next(long minValue, long maxValue)

Parameters

minValue long

minimum value to generate (inclusive).

maxValue long

maximum value to generate (exclusive).

Returns

long

The random long in range [minValue, maxValue).

Remarks

minValue must be less than or equal to maxValue.

Exceptions

ArgumentOutOfRangeException

If minValue is greater than maxValue.

Next(string)

Generates a random char from the given set of characters.

public static char Next(string chars)

Parameters

chars string

The set of allowed characters to generate from.

Returns

char

Remarks

If chars is null or empty, '\0' is returned.