-
Notifications
You must be signed in to change notification settings - Fork 157
Randomizer Methods
The Randomizer object exposed by TestContext.CurrentContext.Random
extends System.Random
to provide random data for a wide range of numeric types as well as enums and strings. Each test context has access to it's own Randomizer which is used to generate random values for the RandomAttribute
as well as for use by the user callng its methods.
The benefit of using Randomizer rather than System.Random
directly is twofold:
- A wide range of types are provided in a uniform manner.
- Randomizer produces repeatable values for the test run so long as no tests are changed and the same seed is used to initialize the run. A future extension is planned, which would provide repeatability at the individual method level, even if other methods are changed.
Returns the next random non-negative int. (Inherited from System.Random
)
Returns the next random non-negative int less than max, which must be positive. (Inherited from System.Random
)
Returns the next random int in the range min to max, excluding max. (Inherited from System.Random
)
Returns the next random uint.
Returns the next random uint less than max.
Returns the next random uint in the range min to max, excluding max.
Returns the next random non-negative long.
Returns the next random non-negative long less than max, which must be positive.
Returns the next random long in the range min to max, excluding max.
Returns the next random ulong.
Returns the next random ulong less than max.
Returns the next random ulong in the range min to max, excluding max.
Returns the next random non-negative short.
Returns the next random non-negative short less than max, which must be positive.
Returns the next random short in the range min to max, excluding max.
Returns the next random ushort.
Returns the next random ushort less than max.
Returns the next random ushort in the range min to max, excluding max.
Returns the next random non-negative sbyte.
Returns the next random non-negative sbyte less than max, which must be positive.
Returns the next random sbyte in the range min to max, excluding max.
Returns the next random byte.
Returns the next random byte less than max.
Returns the next random byte in the range min to max, excluding max.
Returns the next double in the range 0.0 to 1.0, exclusive. (Inherited from System.Random
.)
Returns the next non-negative double less than max.
Returns the next double in the range min to max, excluding max.
Returns the next float in the range 0.0f to 1.0f, exclusive.
Returns the next non-negative float less than max.
Returns the next float in the range min to max, excluding max.
Returns the next non-negative random decimal.
Returns the next non-negative decimal less than max.
Returns the next decimal in the range min to max, excluding max.
- In the current implementation, the scale is always set to zero. That is, the values are all integral, with no decimal places. This may be enhanced in a future release by allowing the user to specify the scale.
- In the third form, an exception is currently thrown if the range is greater than
decimal.MaxValue
. This can only occur if min is negative and max is positive.
Returns a random bool with equal probability of true
or false
.
Returns a random bool with the specified probability of being true
. Probability argument must be in the range 0.0 to 1.0, inclusive.
Returns a random enum value of type T. All the values of the enum are returned with equal probability. Note that this may not be useful in all cases for enums with the FlagsAttribute
specified.
Returns a random enum value of the type specified as an object, which the caller will normally cast to the specified type.
Returns a random string of default length, composed using a default set of characters. In the current implementation, the default length is hard-coded as 25 and the default characters are "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789_".
Returns a random string of the specified length.
Returns a random string of the specified length using the characters in the string given as the second argument.
Copyright (c) 2018 The NUnit Project - Licensed under CC BY-NC-SA 4.0
-
NUnit
-
Release Notes
-
License
- Getting Started
- Writing Tests
- Running Tests
- Extending NUnit
- Technical Notes
-
Release Notes
- NUnit Xamarin Runners
- VS Test Adapter
- VS Test Generator
- NUnit Analyzers