KGy SOFT

SecureRandom Class

KGy SOFT Core Libraries Help
Represents a secure random number generator, which uses a RandomNumberGenerator instance to produce cryptographically secure random numbers. This class is functionally compatible with the Random class.
Inheritance Hierarchy

SystemObject
  SystemRandom
    KGySoft.Security.CryptographySecureRandom

Namespace:  KGySoft.Security.Cryptography
Assembly:  KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 5.0.0-rc.1
Syntax

public class SecureRandom : Random, 
	IDisposable

The SecureRandom type exposes the following members.

Constructors

  NameDescription
Public methodSecureRandom
Initializes a new instance of the SecureRandom class. To generate cryptographically secure random numbers, an RNGCryptoServiceProvider will be used internally.
Public methodSecureRandom(RandomNumberGenerator)
Initializes a new instance of the SecureRandom class.
Top
Methods

  NameDescription
Public methodDispose
Disposes the current SecureRandom instance.
Protected methodDispose(Boolean)
Releases unmanaged and - optionally - managed resources.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodNext
Returns a non-negative random integer.
(Overrides RandomNext.)
Public methodNext(Int32)
Returns a non-negative random integer that is less than the specified maximum.
(Overrides RandomNext(Int32).)
Public methodNext(Int32, Int32)
Returns a random integer that is within a specified range.
(Overrides RandomNext(Int32, Int32).)
Public methodNextBytes
Fills the elements of a specified array of bytes with random numbers.
(Overrides RandomNextBytes(Byte).)
Public methodNextDouble
Returns a random floating-point number that is greater than or equal to 0.0, and less than 1.0.
(Overrides RandomNextDouble.)
Protected methodSample
Returns a random floating-point number between 0.0 and 1.0.
(Overrides RandomSample.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods

  NameDescription
Public Extension MethodConvert(Type, CultureInfo)Overloaded.
Converts an Object specified in the obj parameter to the desired targetType.
See the Examples section of the generic ConvertTTarget(Object, CultureInfo) overload for an example.
(Defined by ObjectExtensions.)
Public Extension MethodCode exampleConvertTTarget(CultureInfo)Overloaded.
Converts an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions.)
Public Extension MethodIn (Defined by ObjectExtensions.)
Public Extension MethodNextBoolean
Returns a random Boolean value.
(Defined by RandomExtensions.)
Public Extension MethodNextByteOverloaded.
Returns a random Byte value.
(Defined by RandomExtensions.)
Public Extension MethodNextByte(Byte, Boolean)Overloaded.
Returns a random Byte value that is less or equal to the specified maxValue.
(Defined by RandomExtensions.)
Public Extension MethodNextByte(Byte, Byte, Boolean)Overloaded.
Returns a random Byte value that is within a specified range.
(Defined by RandomExtensions.)
Public Extension MethodNextBytes
Returns an Array of random bytes that has the specified length.
(Defined by RandomExtensions.)
Public Extension MethodNextChar
Returns a random Char value that is within a specified range.
(Defined by RandomExtensions.)
Public Extension MethodNextDate
Returns a random DateTime that is between the specified range and has only date component.
(Defined by RandomExtensions.)
Public Extension MethodNextDateTime
Returns a random DateTime that is between the specified range.
(Defined by RandomExtensions.)
Public Extension MethodNextDateTimeOffset
Returns a random DateTimeOffset that is between the specified range.
(Defined by RandomExtensions.)
Public Extension MethodNextDecimalOverloaded.
Returns a random Decimal value that is greater than or equal to 0.0 and less than 1.0.
(Defined by RandomExtensions.)
Public Extension MethodNextDecimal(Decimal, FloatScale)Overloaded.
Returns a random Decimal value that is less or equal to the specified maxValue.
(Defined by RandomExtensions.)
Public Extension MethodNextDecimal(Decimal, Decimal, FloatScale)Overloaded.
Returns a random Decimal value that is within a specified range.
(Defined by RandomExtensions.)
Public Extension MethodNextDouble(Double, FloatScale)Overloaded.
Returns a random Double value that is less or equal to the specified maxValue.
(Defined by RandomExtensions.)
Public Extension MethodNextDouble(Double, Double, FloatScale)Overloaded.
Returns a random Double value that is within a specified range.
(Defined by RandomExtensions.)
Public Extension MethodNextEnumTEnum
Returns a random TEnum value.
(Defined by RandomExtensions.)
Public Extension MethodNextGuid
Returns a random RFC 4122 compliant Guid value generated by using the specified Random instance.
(Defined by RandomExtensions.)
Public Extension MethodNextInt16Overloaded.
Returns a random Int16 value.
(Defined by RandomExtensions.)
Public Extension MethodNextInt16(Int16, Boolean)Overloaded.
Returns a random Int16 value that is less or equal to the specified maxValue.
(Defined by RandomExtensions.)
Public Extension MethodNextInt16(Int16, Int16, Boolean)Overloaded.
Returns a random Int16 value that is within a specified range.
(Defined by RandomExtensions.)
Public Extension MethodNextInt32Overloaded.
Returns a random Int32 value.
(Defined by RandomExtensions.)
Public Extension MethodNextInt32(Int32, Boolean)Overloaded.
Returns a random Int32 value that is less or equal to the specified maxValue.
(Defined by RandomExtensions.)
Public Extension MethodNextInt32(Int32, Int32, Boolean)Overloaded.
Returns a random Int32 value that is within a specified range.
(Defined by RandomExtensions.)
Public Extension MethodNextInt64Overloaded.
Returns a random Int64 value.
(Defined by RandomExtensions.)
Public Extension MethodNextInt64(Int64, Boolean)Overloaded.
Returns a random Int64 value that is less or equal to the specified maxValue.
(Defined by RandomExtensions.)
Public Extension MethodNextInt64(Int64, Int64, Boolean)Overloaded.
Returns a random Int64 value that is within a specified range.
(Defined by RandomExtensions.)
Public Extension MethodNextObject(Type, GenerateObjectSettings)Overloaded.
Returns a random object of the specified type or   if type cannot be instantiated with the provided settings.
(Defined by RandomExtensions.)
Public Extension MethodNextObjectT(GenerateObjectSettings)Overloaded.
Returns a random object of type T or the default value of T if T cannot be instantiated with the provided settings.
See the Remarks section for details.
(Defined by RandomExtensions.)
Public Extension MethodNextSByteOverloaded.
Returns a random SByte value.
(Defined by RandomExtensions.)
Public Extension MethodNextSByte(SByte, Boolean)Overloaded.
Returns a random SByte value that is less or equal to the specified maxValue.
(Defined by RandomExtensions.)
Public Extension MethodNextSByte(SByte, SByte, Boolean)Overloaded.
Returns a random SByte value that is within a specified range.
(Defined by RandomExtensions.)
Public Extension MethodNextSingleOverloaded.
Returns a random Single value that is greater than or equal to 0.0 and less than 1.0.
(Defined by RandomExtensions.)
Public Extension MethodNextSingle(Single, FloatScale)Overloaded.
Returns a random Single value that is less or equal to the specified maxValue.
(Defined by RandomExtensions.)
Public Extension MethodNextSingle(Single, Single, FloatScale)Overloaded.
Returns a random Single value that is within a specified range.
(Defined by RandomExtensions.)
Public Extension MethodNextString(Int32, Int32, String)Overloaded.
Returns a random String that has the length between the specified range and consists of the specified allowedCharacters.
(Defined by RandomExtensions.)
Public Extension MethodNextString(Int32, Int32, StringCreation)Overloaded.
Returns a random String using the specified strategy that has the length between the specified range.
(Defined by RandomExtensions.)
Public Extension MethodNextTimeSpan
Returns a random TimeSpan that is between the specified range.
(Defined by RandomExtensions.)
Public Extension MethodNextUInt16Overloaded.
Returns a random UInt16 value.
(Defined by RandomExtensions.)
Public Extension MethodNextUInt16(UInt16, Boolean)Overloaded.
Returns a random UInt16 value that is less or equal to the specified maxValue.
(Defined by RandomExtensions.)
Public Extension MethodNextUInt16(UInt16, UInt16, Boolean)Overloaded.
Returns a random UInt16 value that is within a specified range.
(Defined by RandomExtensions.)
Public Extension MethodNextUInt32Overloaded.
Returns a random UInt32 value.
(Defined by RandomExtensions.)
Public Extension MethodNextUInt32(UInt32, Boolean)Overloaded.
Returns a random UInt32 value that is less or equal to the specified maxValue.
(Defined by RandomExtensions.)
Public Extension MethodNextUInt32(UInt32, UInt32, Boolean)Overloaded.
Returns a random UInt32 value that is within a specified range.
(Defined by RandomExtensions.)
Public Extension MethodNextUInt64Overloaded.
Returns a random UInt64 value.
(Defined by RandomExtensions.)
Public Extension MethodNextUInt64(UInt64, Boolean)Overloaded.
Returns a random UInt64 value that is less or equal to the specified maxValue.
(Defined by RandomExtensions.)
Public Extension MethodNextUInt64(UInt64, UInt64, Boolean)Overloaded.
Returns a random UInt64 value that is within a specified range.
(Defined by RandomExtensions.)
Public Extension MethodTryConvert(Type, Object)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)
Public Extension MethodTryConvert(Type, CultureInfo, Object)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)
Public Extension MethodTryConvertTTarget(TTarget)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired TTarget.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions.)
Public Extension MethodTryConvertTTarget(CultureInfo, TTarget)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired TTarget.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions.)
Top
Remarks

Note Note
Please note that SecureRandom class implements the IDisposable interface so make sure you dispose it (or use it in a using block) if not used in a static context.
See Also

Reference

SystemRandom