Sample code for 30+ languages & platforms
VBScript

Generating Random ASCII Strings

See more PRNG Examples

Demonstrates how to generate random us-ascii strings.

Chilkat VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

' This example assumes the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.

success = 0

set fortuna = CreateObject("Chilkat.Prng")

' Generate random strings having only lowercase chars (a-z)
' Disallow digits and uppercase and only allow lowercase
bDigits = 0
bUppercase = 0
bLowercase = 1

outFile.WriteLine("-- only lowercase alpha (a-z)")
For i = 1 To 10
    ' Generate 20-character strings.
    outFile.WriteLine(fortuna.RandomString(20,bDigits,bLowercase,bUppercase))
Next

' Allow both lowercase and uppercase alpha chars
bUppercase = 1
outFile.WriteLine("-- lower and uppercase alpha (a-zA-Z)")
For i = 1 To 10
    ' Generate 20-character strings.
    outFile.WriteLine(fortuna.RandomString(20,bDigits,bLowercase,bUppercase))
Next

' Allow digits (0-9)
bDigits = 1
outFile.WriteLine("-- digits and lower/uppercase alpha (0-9a-zA-Z)")
For i = 1 To 10
    ' Generate 20-character strings.
    outFile.WriteLine(fortuna.RandomString(20,bDigits,bLowercase,bUppercase))
Next

' Allow only digits (0-9)
bUppercase = 0
bLowercase = 0
outFile.WriteLine("-- only digits (0-9)")
For i = 1 To 10
    ' Generate 20-character strings.
    outFile.WriteLine(fortuna.RandomString(20,bDigits,bLowercase,bUppercase))
Next

outFile.Close