random numbers and letters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff

    random numbers and letters

    hey 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(st rSeed)
    Dim i, nSeed
    nSeed = CLng(0)
    For i = 1 To Len(strSeed)
    nSeed = nSeed Xor ((256 * ((i - 1) Mod 4) * AscB(Mid(strSee d, i, 1))))
    Next

    Randomize nSeed
    End Sub
    '----------
    Function GeneratePasswor d(nLength)
    Dim i, bMadeConsonant, c, nRnd

    Const strDoubleConson ants = "bdfglmnpst "
    Const strConsonants = "bcdfghklmnpqrs tv"
    Const strVocal = "aeiou"
    GeneratePasswor d = ""
    bMadeConsonant = False
    For i = 0 To nLength

    nRnd = Rnd

    If GeneratePasswor d <"" AND _
    (bMadeConsonant <True) AND (nRnd < 0.15) Then

    c = Mid(strDoubleCo nsonants, Len(strDoubleCo nsonants) * Rnd + 1, 1)
    c = c & c
    i = i + 1
    bMadeConsonant = True
    Else

    If (bMadeConsonant <True) And (nRnd < 0.95) Then

    c = Mid(strConsonan ts, Len(strConsonan ts) * Rnd + 1, 1)
    bMadeConsonant = True

    Else

    c = Mid(strVocal, Len(strVocal) * Rnd + 1, 1)
    bMadeConsonant = False
    End If
    End If


    GeneratePasswor d = GeneratePasswor d & c
    Next


    If Len(GeneratePas sword nLength) Then
    GeneratePasswor d = Left(GeneratePa ssword, nLength)
    End If
    End Function
    '----------
    StrRandomize CStr(Now) & CStr(Rnd)
    var_var = GeneratePasswor d(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


  • Jeff

    #2
    Re: random numbers and letters

    scratch that. one of these days I will learn to just think!!

    just added 1234567890 in the Const strConsonants = "bcdfghklmnpqrs tv"
    line, all is well


    thanks


    "Jeff" <bam@gig-gamers.comwrote in message
    news:460eb926$0 $18888$4c368faf @roadrunner.com ...
    hey 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(st rSeed)
    Dim i, nSeed
    nSeed = CLng(0)
    For i = 1 To Len(strSeed)
    nSeed = nSeed Xor ((256 * ((i - 1) Mod 4) * AscB(Mid(strSee d, i, 1))))
    Next
    >
    Randomize nSeed
    End Sub
    '----------
    Function GeneratePasswor d(nLength)
    Dim i, bMadeConsonant, c, nRnd
    >
    Const strDoubleConson ants = "bdfglmnpst "
    Const strConsonants = "bcdfghklmnpqrs tv"
    Const strVocal = "aeiou"
    GeneratePasswor d = ""
    bMadeConsonant = False
    For i = 0 To nLength
    >
    nRnd = Rnd
    >
    If GeneratePasswor d <"" AND _
    (bMadeConsonant <True) AND (nRnd < 0.15) Then
    >
    c = Mid(strDoubleCo nsonants, Len(strDoubleCo nsonants) * Rnd + 1, 1)
    c = c & c
    i = i + 1
    bMadeConsonant = True
    Else
    >
    If (bMadeConsonant <True) And (nRnd < 0.95) Then
    >
    c = Mid(strConsonan ts, Len(strConsonan ts) * Rnd + 1, 1)
    bMadeConsonant = True
    >
    Else
    >
    c = Mid(strVocal, Len(strVocal) * Rnd + 1, 1)
    bMadeConsonant = False
    End If
    End If
    >
    >
    GeneratePasswor d = GeneratePasswor d & c
    Next
    >
    >
    If Len(GeneratePas sword nLength) Then
    GeneratePasswor d = Left(GeneratePa ssword, nLength)
    End If
    End Function
    '----------
    StrRandomize CStr(Now) & CStr(Rnd)
    var_var = GeneratePasswor d(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
    >

    Comment

    Working...