EzRand Component

Properties   Methods   Events   Config Settings   Errors  

The EzRand component can be used to generate random numbers or bytes using a variety of algorithms.

Syntax

nsoftware.IPWorksCData.EzRand

Remarks

The EzRand component can be used to generate random numbers or bytes using a variety of algorithms and implementations.

To begin first set the Algorithm property to the desired value. This property specifies the algorithm and implementation that will be used to generate the number or bytes. Possible choices include ISAAC, the Microsoft Crypto API, and platform specific random and secure random implementations.

Next set Min and Max to define the acceptable range of values when generating an integer. The Seed property may optionally be set. Then simply call GetNextInt to generate a random number. the RandInt property will be populated with the generated value.

To generate a random set of bytes set RandBytesLength to the desired number of bytes and call GetNextBytes.

Property List


The following is the full list of the properties of the component with short descriptions. Click on the links for further details.

Algorithm The random number algorithm.
Max The exclusive upper bound.
Min The inclusive lower bound.
RandBytes The random byte array.
RandBytesLength The length of the byte array to be generated.
RandInt The random integer.
Seed The seed.

Method List


The following is the full list of the methods of the component with short descriptions. Click on the links for further details.

Config Sets or retrieves a configuration setting.
GetNextBytes Generates a sequence of random bytes.
GetNextInt Generates a random integer.
Reset Resets the component.

Event List


The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.

Error Fired when information is available about errors during data delivery.

Config Settings


The following is a list of config settings for the component with short descriptions. Click on the links for further details.

OutputEncoding The encoding applied to the generated bytes.

Algorithm Property (EzRand Component)

The random number algorithm.

Syntax

public EzRandAlgorithms Algorithm { get; set; }

enum EzRandAlgorithms { raISAAC, raMSCryptoAPI, raPlatform, raSecurePlatform, raRC4Random }
Public Property Algorithm As EzrandAlgorithms

Enum EzRandAlgorithms raISAAC raMSCryptoAPI raPlatform raSecurePlatform raRC4Random End Enum

Default Value

0

Remarks

This property specifies the algorithm used to generate the random number or bytes. Possible values are:

0 (raISAAC) ISAAC (indirection, shift, accumulate, add, and count)
1 (raMSCryptoAPI) The Microsoft Crypto API. This is only available on Windows.
2 (raPlatform) The platform's random implementation.
3 (raSecurePlatform) The platform's secure random implementation. This is only applicable in .NET and Java. In .NET the component uses the "RNGCryptoServiceProvider" class. In Java the component uses the "SecureRandom" class.
4 (raRC4Random) RC4 based random implementation.

Max Property (EzRand Component)

The exclusive upper bound.

Syntax

public int Max { get; set; }
                
Public Property Max As Integer
                

Default Value

100

Remarks

This property specifies the exclusive upper bound of the random integer to be generated. The value must be greater than Min. The default value is 100.

Min Property (EzRand Component)

The inclusive lower bound.

Syntax

public int Min { get; set; }
                
Public Property Min As Integer
                

Default Value

0

Remarks

This property specifies the inclusive lower bound of the random integer to be generated. The value must be less than Max, and must not be negative. The default value is 0.

RandBytes Property (EzRand Component)

The random byte array.

Syntax

public string RandBytes { get; }
public byte[] RandBytesB { get; }
                
Public ReadOnly Property RandBytes As String
Public ReadOnly Property RandBytesB As Byte()
                

Default Value

""

Remarks

This property holds the random byte array generated by calling GetNextBytes.

This property is read-only.

RandBytesLength Property (EzRand Component)

The length of the byte array to be generated.

Syntax

public int RandBytesLength { get; set; }
                
Public Property RandBytesLength As Integer
                

Default Value

16

Remarks

This property specifies the length of the random byte array to be generated. The RandBytes property will hold the byte array after GetNextBytes is called. The default value is 16.

RandInt Property (EzRand Component)

The random integer.

Syntax

public int RandInt { get; }
                
Public ReadOnly Property RandInt As Integer
                

Default Value

0

Remarks

This property holds the random integer generated by calling GetNextInt.

This property is read-only.

Seed Property (EzRand Component)

The seed.

Syntax

public string Seed { get; set; }
public byte[] SeedB { get; set; }
                
Public Property Seed As String
Public Property SeedB As Byte()
                

Default Value

""

Remarks

This property specifies the seed. This value is optional. If not specified and a seed is required the component will use the current time.

Seed Notes

  • When Algorithm is set to 0 (raISAAC) the component uses the leftmost 256 bytes.
  • When Algorithm is set to 1 (raMSCryptoAPI) the seed is ignored.
  • When Algorithm is set to 2 (raPlatform) the component uses the leftmost 4 bytes.
  • When Algorithm is set to 3 (raSecurePlatform) in .NET the seed is ignored. The seed is applicable in Java.

Config Method (EzRand Component)

Sets or retrieves a configuration setting.

Syntax

public string Config(string configurationString);
                
Public Function Config(ByVal ConfigurationString As String) As String
                

Remarks

Config is a generic method available in every component. It is used to set and retrieve configuration settings for the component.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.

GetNextBytes Method (EzRand Component)

Generates a sequence of random bytes.

Syntax

public void GetNextBytes();
                
Public Sub GetNextBytes()
                

Remarks

This method generates a new sequence of random bytes. The RandBytesLength property specifies the length of the byte array. After calling this method the RandBytes will hold the random bytes. The following properties are applicable when calling this method:

GetNextInt Method (EzRand Component)

Generates a random integer.

Syntax

public void GetNextInt();
                
Public Sub GetNextInt()
                

Remarks

This method generates a random integer. The Min and Max properties define the minimum and maximum values. After calling this method the RandInt property will hold the integer. The following properties are applicable when calling this method:

Reset Method (EzRand Component)

Resets the component.

Syntax

public void Reset();
                
Public Sub Reset()
                

Remarks

When called, the component will reset all of its properties to their default values.

Error Event (EzRand Component)

Fired when information is available about errors during data delivery.

Syntax

public event OnErrorHandler OnError;

public delegate void OnErrorHandler(object sender, EzRandErrorEventArgs e);

public class EzRandErrorEventArgs : EventArgs {
  public int ErrorCode { get; }
  public string Description { get; }
}
                
Public Event OnError As OnErrorHandler

Public Delegate Sub OnErrorHandler(sender As Object, e As EzRandErrorEventArgs)

Public Class EzRandErrorEventArgs Inherits EventArgs
  Public ReadOnly Property ErrorCode As Integer
  Public ReadOnly Property Description As String
End Class
                

Remarks

The Error event is fired in case of exceptional conditions during message processing. Normally the component throws an exception.

The ErrorCode parameter contains an error code, and the Description parameter contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the Error Codes section.

Config Settings (EzRand Component)

The component accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

EzRand Config Settings

OutputEncoding:   The encoding applied to the generated bytes.

This setting optionally specifies an encoding to apply to the bytes generated when GetNextBytes is called. This may be useful in situations where the bytes are displayed or transmitted as text. Possible values are:

  • 0 (none - default)
  • 1 (Base64)
  • 2 (Hex)
  • 3 (Base64URL)

The RandBytes property will hold the string.

Trappable Errors (EzRand Component)

EzRand Errors

101   Unsupported algorithm.
105   Invalid Min, Max, or RandomBytesLength value.