random numbers and letters
am 31.03.2007 22:44:55 von jeffhey gang.
I have a code to create a random string of letters. The number of them can
be whatever I desire.
what i would like to do, is have it both letters and integers. how would i
modify this code to allow that.
'***** make random password ******
Sub StrRandomize(strSeed)
Dim i, nSeed
nSeed = CLng(0)
For i = 1 To Len(strSeed)
nSeed = nSeed Xor ((256 * ((i - 1) Mod 4) * AscB(Mid(strSeed, i, 1))))
Next
Randomize nSeed
End Sub
'----------
Function GeneratePassword(nLength)
Dim i, bMadeConsonant, c, nRnd
Const strDoubleConsonants = "bdfglmnpst"
Const strConsonants = "bcdfghklmnpqrstv"
Const strVocal = "aeiou"
GeneratePassword = ""
bMadeConsonant = False
For i = 0 To nLength
nRnd = Rnd
If GeneratePassword <> "" AND _
(bMadeConsonant <> True) AND (nRnd < 0.15) Then
c = Mid(strDoubleConsonants, Len(strDoubleConsonants) * Rnd + 1, 1)
c = c & c
i = i + 1
bMadeConsonant = True
Else
If (bMadeConsonant <> True) And (nRnd < 0.95) Then
c = Mid(strConsonants, Len(strConsonants) * Rnd + 1, 1)
bMadeConsonant = True
Else
c = Mid(strVocal, Len(strVocal) * Rnd + 1, 1)
bMadeConsonant = False
End If
End If
GeneratePassword = GeneratePassword & c
Next
If Len(GeneratePassword > nLength) Then
GeneratePassword = Left(GeneratePassword, nLength)
End If
End Function
'----------
StrRandomize CStr(Now) & CStr(Rnd)
var_var = GeneratePassword(6)
'**************************************
this gives me 6 letters at random.
for example utjand
i would like it to give say 3 letters and 3 numbers. is this possible with
the code i have?
TIA
Bam