Sample code for 30+ languages & platforms
VB.NET

Generating Random ASCII Strings

See more PRNG Examples

Demonstrates how to generate random us-ascii strings.

Chilkat VB.NET Downloads

VB.NET
Dim success As Boolean = False

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

success = False

Dim fortuna As New Chilkat.Prng

Dim bDigits As Boolean
Dim bLowercase As Boolean
Dim bUppercase As Boolean

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

Dim i As Integer

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

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

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

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