Class RandomValueEx
Class containing some methods to generate random values.
Inheritance
Inherited Members
Namespace:Extend
Assembly:Extend.dll
Syntax
public static class RandomValueEx
Methods
| Improve this Doc View SourceGetRandomBoolean()
Gets a random Boolean value.
Declaration
public static bool GetRandomBoolean()
Returns
Type | Description |
---|---|
System.Boolean | A random Boolean value. |
GetRandomByte()
Gets a random System.Byte value.
Declaration
public static byte GetRandomByte()
Returns
Type | Description |
---|---|
System.Byte | A random System.Byte value. |
GetRandomChar()
Gets random char.
Declaration
public static char GetRandomChar()
Returns
Type | Description |
---|---|
System.Char | A random char. |
GetRandomDateTime(Nullable<DateTime>, Nullable<DateTime>)
Gets a random date-time value between the given minimum and maximum.
Declaration
public static DateTime GetRandomDateTime(DateTime? min = null, DateTime? max = null)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<T><System.DateTime> | min | The minimum value. |
System.Nullable<T><System.DateTime> | max | The maximum value. |
Returns
Type | Description |
---|---|
System.DateTime | Returns the generated random date-time value. |
Remarks
Default value for minimum is: 01.01.1753. Default value for maximum is: 31.12.9999.
GetRandomDouble(Double, Double)
Gets a random System.Double value which is in the specified range.
Declaration
public static double GetRandomDouble(double min = -1.7976931348623157E+308, double max = 1.7976931348623157E+308)
Parameters
Type | Name | Description |
---|---|---|
System.Double | min | The inclusive min bound. |
System.Double | max | The exclusive maximum bound. Must be greater than min. |
Returns
Type | Description |
---|---|
System.Double | A random System.Double value. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | min is greater than max |
GetRandomEnum<T>()
Gets a random value of the enumeration of the specified type.
Declaration
public static T GetRandomEnum<T>()where T : struct
Returns
Type | Description |
---|---|
T | A random value of the enumeration of the specified type. |
Type Parameters
Name | Description |
---|---|
T | The type of the enumeration. |
GetRandomInt16(Int16, Int16)
Gets a random integer value which is in the specified range.
Declaration
public static short GetRandomInt16(short min = -32768, short max = 32767)
Parameters
Type | Name | Description |
---|---|---|
System.Int16 | min | The inclusive min bound. |
System.Int16 | max | The exclusive maximum bound. Must be greater than min. |
Returns
Type | Description |
---|---|
System.Int16 | A random integer value. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | min is greater than max |
GetRandomInt32(Int32, Int32)
Gets a random integer value which is in the specified range.
Declaration
public static int GetRandomInt32(int min = -2147483648, int max = 2147483647)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | min | The inclusive min bound. |
System.Int32 | max | The exclusive maximum bound. Must be greater than min. |
Returns
Type | Description |
---|---|
System.Int32 | A random integer value. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | min is greater than max |
GetRandomInt64(Int64, Int64)
Gets a random long value which is in the specified range.
Declaration
public static long GetRandomInt64(long min = -9223372036854775808L, long max = 9223372036854775807L)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | min | The inclusive min bound. |
System.Int64 | max | The exclusive maximum bound. Must be greater than min. |
Returns
Type | Description |
---|---|
System.Int64 | A random long value. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | min is greater than max |
GetRandomString()
Gets random string.
Declaration
public static string GetRandomString()
Returns
Type | Description |
---|---|
System.String | A random string. |
GetRandomStrings(Nullable<Int32>)
Gets a list of random strings.
Declaration
public static List<string> GetRandomStrings(int ? numberOfItems = null)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<T><System.Int32> | numberOfItems | The number of items to generate. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<T><System.String> | A list of random strings. |