Development‎ > ‎VBScript‎ > ‎

Generate Random String


'*********************************************************************************
'* Configuration section of the script
'*********************************************************************************
Const PASS_LEN_MIN = 4
Const PASS_LEN_MAX = 9
Const PASSWORD_COUNT = 100
Const DICTIONARY_PATH = "C:\PasswordDictionary.txt"
Dim aEntropy : aEntropy = Array("A" ,"B" ,"C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S", "T", "U", "V", "W", "X", "Y", "Z", "a" ,"b" ,"c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
'*********************************************************************************
 
 
Randomize
 
 
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(DICTIONARY_PATH, 2, True)
 
Dim iPasswordLength
For iPasswordIndex = 1 To PASSWORD_COUNT - 1
      iPasswordLength = Int((PASS_LEN_MAX - PASS_LEN_MIN + 1) * Rnd + PASS_LEN_MIN)
      f.WriteLine GenerateRandomString(iPasswordLength)
Next
 
f.Close
 
Set f= Nothing
Set fso = Nothing
 
 
 
'*********************************************************************************
'* Function signature:
'* Description: Function which generates random strings
'*                  
'*
'* Parameters
'*
'*
'*
'* Return Value
'*
'*********************************************************************************
Function GenerateRandomString(iPasswordLength)
 
      Dim sPassword
     
      For iPasswordLetter = 0 To iPasswordLength
            iRandomNumber = Int((UBound(aEntropy) + 1) * Rnd)
            sPassword = sPassword & aEntropy(iRandomNumber)
      Next
     
      GenerateRandomString = sPassword
End Function

Comments