Function Random Values Class

RandomStringFast

Returns a random string whose length is between vMinLength and vMaxLength characters inclusive and which will be composed of the characters in string vAlphabet. Faster version of the RandomString function which has restrictive argument types and no argument validation.

Signature (Visual Basic / VBA)

Public Function RandomStringFast( _
      ByRef vMinLength As Long _
    , ByRef vMaxLength As Long _
    , ByRef vAlphabet As String _
    ) As String

Code Example

    Rnd(-1) = 0.224007
    RandomStringFast(0, 16, CryptoAlphabet) = ""
    RandomStringFast(0, 16, CryptoAlphabet) = "D"
    RandomStringFast(0, 16, CryptoAlphabet) = "OM "
    RandomStringFast(10, 10, CryptoAlphabet) = "JRDLBUKXHU"
    RandomStringFast(10, 10, CryptoAlphabet) = "PZKSLARUXW"
    RandomStringFast(10, 10, CryptoAlphabet) = "CZANUGPSZU"
    CryptoAlphabet = " ABCDEFGHIJKLMNOPQRSTUVWXYZ"

Parameters

Parameter Description
vMinLength Minimum length of the random string that will be returned. This argument is never modified even though it is passed by-reference.
vMaxLength Maximum length of the random string that will be returned. This argument is never modified even though it is passed by-reference. Function returns an empty string if vMinLength > (is greater than) vMaxLength.
vAlphabet String containing that the characters that will be used to compose the random string. This argument is never modified even though it is passed by-reference. Function returns an empty string if the alphabet vAlphabet is an empty string.

Notes & Version History

Note The call to the Visual Basic Rnd function in the above example seeds the Visual Basic random number generator so that the sample results can be reproduced. There is generally no need to call the Rnd function within your programs since Entisoft Tools initializes the Visual Basic random number generator once with "Randomize" statement.