Table of Contents

Class RandomGenerator

Namespace
NUnit.Framework.Internal
Assembly
nunit.framework.dll

RandomGenerator returns a set of random _values in a repeatable way, to allow re-running of tests if necessary.

This class is internal to the framework but exposed externally to through the TestContext the class is used to allow for obtaining repeatable random _values during a tests execution. this class should not be used inside the framework only with a TestMethod.

public class RandomGenerator
Inheritance
RandomGenerator
Inherited Members

Constructors

RandomGenerator(int)

Constructor requires Seed value in order to store it for use in Random creation

public RandomGenerator(int seed)

Parameters

seed int

Fields

seed

Seed for the wrapped Random

public readonly int seed

Field Value

int

Methods

GetBool()

Get Random Boolean value

public bool GetBool()

Returns

bool

bool

GetBool(double)

Get Random Boolean value based on the probability of that value being true

public bool GetBool(double probability)

Parameters

probability double

Returns

bool

bool

GetByte()

Get Next Byte from Random

public byte GetByte()

Returns

byte

byte

GetByte(byte, byte)

Get Next Byte within the specified min & max from Random

public byte GetByte(byte min, byte max)

Parameters

min byte
max byte

Returns

byte

byte

GetDouble()

Get Next Double from Random

public double GetDouble()

Returns

double

GetEnum<T>()

Return a random enum value representation of the specified Type

public T GetEnum<T>()

Returns

T

T

Type Parameters

T

GetFloat()

Get Next Float from Random

public float GetFloat()

Returns

float

GetInt()

Get Next Integer from Random

public int GetInt()

Returns

int

int

GetInt(int, int)

Get Next Integer within the specified min & max from Random

public int GetInt(int min, int max)

Parameters

min int
max int

Returns

int

int

GetShort()

Get Next Short from Random

public short GetShort()

Returns

short

short

GetShort(short, short)

Get Next Short within the specified min & max from Random

public short GetShort(short min, short max)

Parameters

min short
max short

Returns

short

short