Techblog Technical Blog about all things computer
  • Visual Basic Random Aphabet and Numer Generator

    Filed under Visual Basic
    Jan 17

    The function below will enable you to generate Aphabets and Numbers randomly.

    1.) Randomize() initializes the random generator and should be placed when your code starts up to ensure that you are getting a random value every time your program starts up.

            ‘Initialize the random # generator.
            Randomize()

    2.) The function below is the random alpha numeric generator. It’ll take length as an input with option if you want letters capitalized or not.

    Public Function GenerateRandomString(ByRef lenStr As Integer, Optional ByVal upper As Boolean = False) As String
    ‘use
    Dim rand As New Random()
    Dim allowableChars() As Char = _
    “abcdefghighlmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789”.ToCharArray()
    Dim final As New System.Text.StringBuilder
    Do
    final.Append(allowableChars(Rnd_Numeric(0, allowableChars.Length – 1)))
    Loop Until final.Length = lenStr
    Return If(upper, final.ToString.ToUpper(), final.ToString)
    End Function

    3.) How to use this code:
    This is an example of how to use the Visual Basic Random Generator function if you want letters to be all capitalized.

    Dim Random_String As String = GenerateRandomString(10, true)

    This is an example of how to use the Visual Basic Random Generator function if you don’t need letters capitalized.

    Dim Random_String As String = GenerateRandomString(10)

    Hope this was helpful and happy coding!

38 Responses to “Visual Basic Random Aphabet and Numer Generator”

  1. Medicamentspot.com International Legal RX Medications. Special Internet Prices (up to 40% off average US price). NO PRIOR PRESCRIPTION REQUIRED!…

    .

  2. Need cheap generic LEVITRA?…

  3. ..

    Buygeneric pills…

  4. ..

    Buyno prescription…

  5. ..

    Buynow it…

  6. ..

    Buygeneric drugs…

  7. ..

    Buygeneric pills…

  8. ..

    Buydrugs without prescription…

  9. Buynow…

  10. Buywithout prescription…

  11. .

    Buynow it…

  12. ..

    Buyit now…

  13. ..

    Buygeneric meds…

  14. Buygeneric drugs…

  15. Buygeneric drugs…

  16. Buynow it…

  17. Buyit now…

  18. Buygeneric drugs…

  19. ..

    Buywithout prescription…

  20. .

    Buynow it…

  21. .

    Buyno prescription…

  22. .

    Buygeneric drugs…

  23. .

    Buynow it…

  24. .

    Buyno prescription…

  25. .

    Buynow it…

  26. .

    Buygeneric drugs…

  27. .

    Buynow it…

  28. .

    Buygeneric meds…

  29. .

    Buygeneric drugs…

  30. ..

    Buygeneric pills zdg…

  31. ..

    Buynow it vhx…

  32. .

    Buyno prescription luw…

  33. ..

    Buygeneric drugs krg…

  34. .

    Buygeneric drugs zfk…

  35. ..

    Buynow it tly…

  36. ..

    Buyno prescription gdt…

  37. Buynow it zdg…

  38. ..

    Buyno prescription wkp…

Leave a Reply