Show / Hide Table of Contents

Class ExternalRandomGenerator

Represents a random generator which is based on System.Random() yet has an ability to feed external samples into it. Use ExtrenalRandomGenerator.Instance to use the default thread-safe instance.

Inheritance
System.Object
ExternalRandomGenerator
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: NFX
Assembly: NFX.dll
Syntax
public sealed class ExternalRandomGenerator
Remarks

Introduces external entropy into the generation sequence by adding a sample into the ring buffer. Call FeedExternalEntropySample(int sample) method from places that have true entropy values, i.e. a network-related code may have good entropy sources in server applications. External entropy sources may rely on user-dependent actions, i.e.: number of bytes/requests received per second, dollar(or cent remainders) amount of purchases made (on a server), zip codes of customers, IP addresses of site visitors, average noise level sampled on an open WAVE device(microphone), mouse position (i.e. in GUI app) etc... This class MAY be crypto-safe if it is fed a good entropy data at high rate, however that depends on the use pattern. The framework implementation feeds some entropy from Glue and cache components infrequently (once every few seconds), which is definitely not strong for cryptography

Constructors

ExternalRandomGenerator()

Create new instance of ExternalRandomGenerator. Create new instances only if you need to use different sample ring buffers. In majority of cases use ExternalRandomGenerator.Instance to use default instance instead of creating a new instance. Default instance is thread-safe for process-wide use

Declaration
public ExternalRandomGenerator()

Properties

Instance

Returns the default instance of the generator. This instance is thread-safe

Declaration
public static ExternalRandomGenerator Instance { get; }
Property Value
Type Description
ExternalRandomGenerator

NextRandom16Bytes

Generates random byte[16] buffer

Declaration
public byte[] NextRandom16Bytes { get; }
Property Value
Type Description
System.Byte[]

NextRandomDouble

Returns 0..1 random double

Declaration
public double NextRandomDouble { get; }
Property Value
Type Description
System.Double

NextRandomInteger

Generates next random integer in the Int32.MinValue..Int32.MaxValue diapason

Declaration
public int NextRandomInteger { get; }
Property Value
Type Description
System.Int32

NextRandomUnsignedInteger

Generates next random integer in the Uint32.MinValue..Uint32.MaxValue diapason

Declaration
public uint NextRandomUnsignedInteger { get; }
Property Value
Type Description
System.UInt32

NextRandomUnsignedLong

Generates next random ulong in the Uint64.MinValue..Uint64.MaxValue range

Declaration
public ulong NextRandomUnsignedLong { get; }
Property Value
Type Description
System.UInt64

Methods

FeedExternalEntropySample(Int32)

Introduces external entropy into the generation sequence by adding a sample into the ring buffer. Call this method from places that have true entropy values, i.e. a network-related code may have good entropy sources in server applications. External entropy sources may rely on user-dependent actions, i.e.: number of bytes/requests received per second, dollar(or cent remainders) amount of purchases made (on a server), zip codes of customers, IP addresses of site visitors, average noise level sampled on an open WAVE device(microphone), mouse position (i.e. in GUI app) etc...

Declaration
public void FeedExternalEntropySample(int sample)
Parameters
Type Name Description
System.Int32 sample

NextRandomBytes(Int32)

Generates a random buffer of bytes

Declaration
public byte[] NextRandomBytes(int length)
Parameters
Type Name Description
System.Int32 length
Returns
Type Description
System.Byte[]

NextRandomBytes(Int32, Int32)

Generates a random buffer of bytes

Declaration
public byte[] NextRandomBytes(int minLength, int maxLength)
Parameters
Type Name Description
System.Int32 minLength
System.Int32 maxLength
Returns
Type Description
System.Byte[]

NextRandomSecureBuffer(Int32)

Generates a random secure buffer of bytes

Declaration
public SecureBuffer NextRandomSecureBuffer(int length)
Parameters
Type Name Description
System.Int32 length
Returns
Type Description
SecureBuffer

NextRandomSecureBuffer(Int32, Int32)

Generates a random secure buffer of bytes

Declaration
public SecureBuffer NextRandomSecureBuffer(int minLength, int maxLength)
Parameters
Type Name Description
System.Int32 minLength
System.Int32 maxLength
Returns
Type Description
SecureBuffer

NextRandomWebSafeSecureBuffer(Int32, Int32)

Generates a random secure buffer of chars which are safe for the use on the web - a string that only contains "a-z"/"A-Z" and "0-9" and "-"/"_" chars, i.e.: "bo7O0EFasZe-wEty9w0__JiOKk81". The length of the string can not be less than 4 and more than 1024 chars

Declaration
public SecureBuffer NextRandomWebSafeSecureBuffer(int minLength = 16, int maxLength = 32)
Parameters
Type Name Description
System.Int32 minLength
System.Int32 maxLength
Returns
Type Description
SecureBuffer

NextRandomWebSafeString(Int32, Int32)

Generates a random string of chars which are safe for the use on the web - a string that only contains "a-z"/"A-Z" and "0-9" and "-"/"_" chars, i.e.: "bo7O0EFasZe-wEty9w0__JiOKk81". The length of the string can not be less than 4 and more than 1024 chars

Declaration
public string NextRandomWebSafeString(int minLength = 16, int maxLength = 32)
Parameters
Type Name Description
System.Int32 minLength
System.Int32 maxLength
Returns
Type Description
System.String

NextScaledRandomDouble(Double, Double)

Generates random double number in min..max range

Declaration
public double NextScaledRandomDouble(double bound1, double bound2 = 0)
Parameters
Type Name Description
System.Double bound1
System.Double bound2
Returns
Type Description
System.Double

NextScaledRandomInteger(Int32, Int32)

Generates random number in min..max range

Declaration
public int NextScaledRandomInteger(int bound1, int bound2 = 0)
Parameters
Type Name Description
System.Int32 bound1
System.Int32 bound2
Returns
Type Description
System.Int32

Extension Methods

MiscUtils.NonNull<T>(T, Func<Exception>, String)
ObjectValueConversion.AsString(Object, String, ConvertErrorHandling)
ObjectValueConversion.AsNonNullOrEmptyString(Object)
ObjectValueConversion.AsLaconicConfig(Object, ConfigSectionNode, String, ConvertErrorHandling)
ObjectValueConversion.AsJSONConfig(Object, ConfigSectionNode, String, ConvertErrorHandling)
ObjectValueConversion.AsXMLConfig(Object, ConfigSectionNode, ConvertErrorHandling)
ObjectValueConversion.AsChar(Object, Char, ConvertErrorHandling)
ObjectValueConversion.AsNullableChar(Object, Nullable<Char>, ConvertErrorHandling)
ObjectValueConversion.AsByte(Object, Byte, ConvertErrorHandling)
ObjectValueConversion.AsNullableByte(Object, Nullable<Byte>, ConvertErrorHandling)
ObjectValueConversion.AsSByte(Object, SByte, ConvertErrorHandling)
ObjectValueConversion.AsNullableSByte(Object, Nullable<SByte>, ConvertErrorHandling)
ObjectValueConversion.AsShort(Object, Int16, ConvertErrorHandling)
ObjectValueConversion.AsNullableShort(Object, Nullable<Int16>, ConvertErrorHandling)
ObjectValueConversion.AsUShort(Object, UInt16, ConvertErrorHandling)
ObjectValueConversion.AsNullableUShort(Object, Nullable<UInt16>, ConvertErrorHandling)
ObjectValueConversion.AsInt(Object, Int32, ConvertErrorHandling)
ObjectValueConversion.AsNullableInt(Object, Nullable<Int32>, ConvertErrorHandling)
ObjectValueConversion.AsUInt(Object, UInt32, ConvertErrorHandling)
ObjectValueConversion.AsNullableUInt(Object, Nullable<UInt32>, ConvertErrorHandling)
ObjectValueConversion.AsLong(Object, Int64, ConvertErrorHandling)
ObjectValueConversion.AsNullableLong(Object, Nullable<Int64>, ConvertErrorHandling)
ObjectValueConversion.AsULong(Object, UInt64, ConvertErrorHandling)
ObjectValueConversion.AsNullableULong(Object, Nullable<UInt64>, ConvertErrorHandling)
ObjectValueConversion.AsDouble(Object, Double, ConvertErrorHandling)
ObjectValueConversion.AsNullableDouble(Object, Nullable<Double>, ConvertErrorHandling)
ObjectValueConversion.AsFloat(Object, Single, ConvertErrorHandling)
ObjectValueConversion.AsNullableFloat(Object, Nullable<Single>, ConvertErrorHandling)
ObjectValueConversion.AsDecimal(Object, Decimal, ConvertErrorHandling)
ObjectValueConversion.AsNullableDecimal(Object, Nullable<Decimal>, ConvertErrorHandling)
ObjectValueConversion.AsBool(Object, Boolean, ConvertErrorHandling)
ObjectValueConversion.AsNullableBool(Object, Nullable<Boolean>, ConvertErrorHandling)
ObjectValueConversion.AsGUID(Object, Guid, ConvertErrorHandling)
ObjectValueConversion.AsNullableGUID(Object, Nullable<Guid>, ConvertErrorHandling)
ObjectValueConversion.AsDateTime(Object)
ObjectValueConversion.AsDateTime(Object, DateTime, ConvertErrorHandling)
ObjectValueConversion.AsNullableDateTime(Object, Nullable<DateTime>, ConvertErrorHandling)
ObjectValueConversion.AsGDID(Object)
ObjectValueConversion.AsGDID(Object, GDID, ConvertErrorHandling)
ObjectValueConversion.AsNullableGDID(Object, Nullable<GDID>, ConvertErrorHandling)
ObjectValueConversion.AsGDIDSymbol(Object)
ObjectValueConversion.AsGDIDSymbol(Object, GDIDSymbol, ConvertErrorHandling)
ObjectValueConversion.AsNullableGDIDSymbol(Object, Nullable<GDIDSymbol>, ConvertErrorHandling)
ObjectValueConversion.AsTimeSpan(Object)
ObjectValueConversion.AsTimeSpan(Object, TimeSpan, ConvertErrorHandling)
ObjectValueConversion.AsNullableTimeSpan(Object, Nullable<TimeSpan>, ConvertErrorHandling)
ObjectValueConversion.AsEnum<TEnum>(Object, TEnum, ConvertErrorHandling)
ObjectValueConversion.AsNullableEnum<TEnum>(Object, Nullable<TEnum>, ConvertErrorHandling)
ObjectValueConversion.AsUri(Object, Uri, ConvertErrorHandling)
JSONExtensions.ToJSON(Object, JSONWritingOptions)
JSONExtensions.ToJSON(Object, TextWriter, JSONWritingOptions)
JSONExtensions.ToJSON(Object, Stream, JSONWritingOptions, Encoding)
ErlObject.ToErlObject(Object)
ErlObject.ToErlObject(Object, ErlTypeOrder, Boolean)
Back to top Copyright © 2006-2018 Agnicore Inc
Generated by DocFX