RandomGen

Ecng.Common

Provides methods for generating random values of various types.

Métodos

GetBool
public static bool GetBool()
result = RandomGen.GetBool()

Returns a random boolean value.

Retorna: A random boolean.

GetByte
public static byte GetByte(byte min, byte max)
result = RandomGen.GetByte(min, max)

Returns a random byte between the specified minimum and maximum values (inclusive).

min
The minimum value.
max
The maximum value.

Retorna: A random byte between min and max.

GetByte
public static byte GetByte(byte max)
result = RandomGen.GetByte(max)

Returns a random byte between 0 and the specified maximum value (inclusive).

max
The maximum value.

Retorna: A random byte between 0 and max.

GetByte
public static byte GetByte()
result = RandomGen.GetByte()

Returns a random byte between 0 and byte.MaxValue.

Retorna: A random byte.

GetBytes
public static byte[] GetBytes(int count)
result = RandomGen.GetBytes(count)

Returns an array of random bytes with the specified count.

count
The number of random bytes to generate.

Retorna: An array of random bytes.

GetBytes
public static void GetBytes(byte[] buffer)
RandomGen.GetBytes(buffer)

Fills the provided array with random bytes.

buffer
The array to fill with random bytes.
GetDate
public static DateTime GetDate(DateTime min, DateTime max)
result = RandomGen.GetDate(min, max)

Returns a random DateTime value between the specified minimum and maximum values.

min
The minimum DateTime value.
max
The maximum DateTime value.

Retorna: A random DateTime between min and max.

GetDate
public static DateTime GetDate()
result = RandomGen.GetDate()

Returns a random DateTime value between DateTime.MinValue and DateTime.MaxValue.

Retorna: A random DateTime.

GetDecimal
public static decimal GetDecimal(decimal min, decimal max, int precision)
result = RandomGen.GetDecimal(min, max, precision)

Returns a random decimal value between the specified minimum and maximum values with the given precision.

min
The minimum decimal value.
max
The maximum decimal value.
precision
The number of decimal places to round the value to.

Retorna: A random decimal value between min and max rounded to the specified precision.

GetDecimal
public static decimal GetDecimal(int integer, int fractional)
result = RandomGen.GetDecimal(integer, fractional)

Returns a random non-zero decimal value with a specified number of integer and fractional digits. Tries up to 10 times to generate a valid number.

integer
The maximum number of digits in the integer part. Default is 8.
fractional
The maximum number of digits in the fractional part. Default is 8.

Retorna: A random decimal value.

GetDouble
public static double GetDouble()
result = RandomGen.GetDouble()

Returns a random double value between 0.0 and 1.0.

Retorna: A random double.

GetDouble
public static double GetDouble(double max)
result = RandomGen.GetDouble(max)

Returns a random double value between 0.0 and the specified maximum value.

max
The maximum value.

Retorna: A random double between 0.0 and max.

GetDouble
public static double GetDouble(double min, double max)
result = RandomGen.GetDouble(min, max)

Returns a random double value between the specified minimum and maximum values.

min
The minimum value.
max
The maximum value.

Retorna: A random double between min and max.

GetElement``1
public static T GetElement<T>(IEnumerable<T> array)
result = RandomGen.GetElement(array)

Returns a random element from the specified collection.

array
The collection of elements.

Retorna: A random element from the collection.

GetEnum
public static object GetEnum(Type enumType)
result = RandomGen.GetEnum(enumType)

Returns a random enum value from the specified enum type.

enumType
The enum type.

Retorna: A random enum value.

GetEnum``1
public static T GetEnum<T>(T min, T max)
result = RandomGen.GetEnum(min, max)

Returns a random enum value between the specified minimum and maximum enum values.

min
The minimum enum value.
max
The maximum enum value.

Retorna: A random enum value between min and max.

GetEnum``1
public static T GetEnum<T>()
result = RandomGen.GetEnum()

Returns a random enum value of type T.

Retorna: A random enum value.

GetEnum``1
public static T GetEnum<T>(IEnumerable<T> values)
result = RandomGen.GetEnum(values)

Returns a random enum value from the specified collection of values.

values
A collection of enum values.

Retorna: A random enum value from the collection.

GetFloat
public static float GetFloat()
result = RandomGen.GetFloat()

Returns a random single-precision floating-point number between 0.0 and 1.0.

Retorna: A random float.

GetFloat
public static float GetFloat(float min, float max)
result = RandomGen.GetFloat(min, max)

Returns a random single-precision floating-point number between the specified minimum and maximum values.

min
The minimum value.
max
The maximum value.

Retorna: A random float between min and max.

GetFloat
public static float GetFloat(float max)
result = RandomGen.GetFloat(max)

Returns a random single-precision floating-point number between 0.0 and the specified maximum value.

max
The maximum value.

Retorna: A random float between 0.0 and max.

GetInt
public static int GetInt(int max)
result = RandomGen.GetInt(max)

Returns a random integer between 0 and the specified maximum value (inclusive).

max
The maximum value.

Retorna: A random integer between 0 and max (inclusive).

GetInt
public static int GetInt()
result = RandomGen.GetInt()

Returns a random non-negative integer.

Retorna: A random integer.

GetInt
public static int GetInt(int min, int max)
result = RandomGen.GetInt(min, max)

Returns a random integer between the specified minimum and maximum values (inclusive).

min
The minimum value.
max
The maximum value.

Retorna: A random integer between min and max (inclusive).

GetLong
public static long GetLong(long min, long max)
result = RandomGen.GetLong(min, max)

Returns a random long value between the specified minimum and maximum values (inclusive).

min
The minimum value.
max
The maximum value.

Retorna: A random long value between min and max (inclusive).

GetLong
public static long GetLong()
result = RandomGen.GetLong()

Returns a random long value between long.MinValue and long.MaxValue.

Retorna: A random long value.

GetSByte
public static sbyte GetSByte()
result = RandomGen.GetSByte()

Returns a random signed byte between sbyte.MinValue and sbyte.MaxValue.

Retorna: A random signed byte.

GetSByte
public static sbyte GetSByte(sbyte min, sbyte max)
result = RandomGen.GetSByte(min, max)

Returns a random signed byte between the specified minimum and maximum values (inclusive).

min
The minimum value.
max
The maximum value.

Retorna: A random signed byte between min and max.

GetSByte
public static sbyte GetSByte(sbyte max)
result = RandomGen.GetSByte(max)

Returns a random signed byte between 0 and the specified maximum value (inclusive).

max
The maximum value.

Retorna: A random signed byte between 0 and max.

GetShort
public static short GetShort(short min, short max)
result = RandomGen.GetShort(min, max)

Returns a random 16-bit signed integer between the specified minimum and maximum values (inclusive).

min
The minimum value.
max
The maximum value.

Retorna: A random short value between min and max.

GetShort
public static short GetShort()
result = RandomGen.GetShort()

Returns a random 16-bit signed integer between short.MinValue and short.MaxValue.

Retorna: A random short value.

GetShort
public static short GetShort(short max)
result = RandomGen.GetShort(max)

Returns a random 16-bit signed integer between 0 and the specified maximum value (inclusive).

max
The maximum value.

Retorna: A random short value between 0 and max.

GetString
public static string GetString(int min, int max)
result = RandomGen.GetString(min, max)

Returns a random Base64 encoded string generated from a random salt.

min
The minimum length for generating the salt.
max
The maximum length for generating the salt.

Retorna: A random Base64 encoded string.

GetTime
public static TimeSpan GetTime()
result = RandomGen.GetTime()

Returns a random TimeSpan value between TimeSpan.MinValue and TimeSpan.MaxValue.

Retorna: A random TimeSpan.

GetTime
public static TimeSpan GetTime(TimeSpan min, TimeSpan max)
result = RandomGen.GetTime(min, max)

Returns a random TimeSpan value between the specified minimum and maximum values.

min
The minimum TimeSpan value.
max
The maximum TimeSpan value.

Retorna: A random TimeSpan between min and max.

GetUInt
public static uint GetUInt()
result = RandomGen.GetUInt()

Returns a random unsigned integer between 0 and uint.MaxValue.

Retorna: A random unsigned integer.

GetUInt
public static uint GetUInt(uint min, uint max)
result = RandomGen.GetUInt(min, max)

Returns a random unsigned integer between the specified minimum and maximum values (inclusive).

min
The minimum value.
max
The maximum value.

Retorna: A random unsigned integer between min and max.

GetUInt
public static uint GetUInt(uint max)
result = RandomGen.GetUInt(max)

Returns a random unsigned integer between 0 and the specified maximum value (inclusive).

max
The maximum value.

Retorna: A random unsigned integer between 0 and max.

GetULong
public static ulong GetULong(ulong min, ulong max)
result = RandomGen.GetULong(min, max)

Returns a random unsigned long value between the specified minimum and maximum values (inclusive).

min
The minimum value.
max
The maximum value.

Retorna: A random unsigned long value between min and max.

GetULong
public static ulong GetULong(ulong max)
result = RandomGen.GetULong(max)

Returns a random unsigned long value between 0 and the specified maximum value (inclusive).

max
The maximum value.

Retorna: A random unsigned long value between 0 and max.

GetULong
public static ulong GetULong()
result = RandomGen.GetULong()

Returns a random unsigned long value between 0 and ulong.MaxValue.

Retorna: A random unsigned long value.

GetUShort
public static ushort GetUShort()
result = RandomGen.GetUShort()

Returns a random 16-bit unsigned integer between 0 and ushort.MaxValue.

Retorna: A random unsigned short value.

GetUShort
public static ushort GetUShort(ushort min, ushort max)
result = RandomGen.GetUShort(min, max)

Returns a random 16-bit unsigned integer between the specified minimum and maximum values (inclusive).

min
The minimum value.
max
The maximum value.

Retorna: A random unsigned short value between min and max.

GetUShort
public static ushort GetUShort(ushort max)
result = RandomGen.GetUShort(max)

Returns a random 16-bit unsigned integer between 0 and the specified maximum value (inclusive).

max
The maximum value.

Retorna: A random unsigned short value between 0 and max.