Utilities.GetRandom method

[The GetRandom method is available for use in the operating systems specified in the Requirements section.]

The GetRandom method generates a secure random number using the default cryptographic service provider (CSP).

Syntax

Utilities.GetRandom( _
  [ ByVal Length ], _
  [ ByVal EncodingType ] _
)

Parameters

Length [in, optional]

The length, in bytes, of the random number to create. The default value is 8 bytes.

EncodingType [in, optional]

A value of the CAPICOM_ENCODING_TYPE enumeration that indicates the type of encoding to use for the generated random number. The default value is CAPICOM_ENCODE_BINARY. This parameter can be one of the following values.

Value Meaning
CAPICOM_ENCODE_ANY
This encoding type is used only when the input data has an unknown encoding type. If this value is used to specify the output's encoding type, CAPICOM_ENCODE_BASE64 will be used instead. Introduced in CAPICOM 2.0.
CAPICOM_ENCODE_BASE64
Data is saved as a base64-encoded string.
CAPICOM_ENCODE_BINARY
Data is saved as a pure binary sequence.

 

Return value

A randomly generated number Length bytes long, with the specified encoding.

Requirements

Requirement Value
Redistributable
CAPICOM 2.0 or later on Windows Server 2003 and Windows XP
DLL
Capicom.dll

See also

Utilities