Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[How to] Create random strings(upper,lower and integers)[Src]
#1
Ill start with saying what this is, the code generates a string with random uppercase,lowercase, and numbers. You can edit how many random characters there will be. Here is the code:
Code:
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MessageBox.Show(Random())
    End Sub
    Public Function Random() As String
        Random = ""
        Const strUpper As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        Const strLower As String = "abcdefghijklmnopqrstuvwxyz"
        Const strNumbers As String = "1234567890"
        Dim strTotal As String
        Dim i As Short
        strTotal = strUpper & strLower & strNumbers
        For i = 1 To CInt("25")
            Random = Random & Mid(strTotal, Int((Rnd() * Len(strTotal)) + 1), 1)
        Next i
    End Function
End Class
Oke now some explanations
Code:
Const strUpper As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        Const strLower As String = "abcdefghijklmnopqrstuvwxyz"
        Const strNumbers As String = "1234567890"
We now have 3 strings, one with uppercase, one with lowercase and one with numbers. Later on we are going to take a random character from the string.
Code:
For i = 1 To CInt("25")
            Random = Random & Mid(strTotal, Int((Rnd() * Len(strTotal)) + 1), 1)
        Next i
We make a loop to get our random string, you can change the length of the string by changing this number "For i = 1 To CInt("25")" if you change the 25 to 4, then our string only will have 4 characters
Reply
#2
Nice job, I don't know what someone may need this for, but great job. At least it works. Big Grin

I am bookmarking this.
[Image: t5BWm.png]
Reply
#3
(04-17-2011, 08:26 AM)The High Roller Wrote: Nice job, I don't know what someone may need this for, but niec job. At least it works. Big Grin

I am bookmarking this.
Thank you for the nice comment Smile

Reply
#4
Good job, i already know this but this is good.
Reply
#5
remember to put "Randomize" in the form load, otherwise the rnd() function will return the same "random" value every time
Reply
#6
Nice share, what can this be used for?
Reply
#7
password generators and stuff
Reply
#8
Oh thanks, i looked for stuff like this my some fake softwareBig Grin
Reply
#9
Thanks mate. This will make it easier for me to do fake keygens, etc.
Reply
#10
A slight change version, with number of random strings to generate.

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If StrLength.TextLength <= 0 Then
            MsgBox("Input string length.")
        Else
            StrOutput.Text = RandomString(StrLength.Text)
        End If
    End Sub

    Function RandomString(ByVal val As Integer) As String
        RandomString = ""
        Const strUpper As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        Const strLower As String = "abcdefghijklmnopqrstuvwxyz"
        Const strNumbers As String = "1234567890"
        Dim strTotal As String = strUpper & strLower & strNumbers
        Dim i As Short

        For i = 1 To CInt(val)
            RandomString = RandomString & Mid(strTotal, Int((Rnd() * Len(strTotal)) + 1), 1)
        Next i
    End Function

Screenshot:
[Image: 3iTgN.png]
USB Anti-virus? Try USB Drive Defender
[Image: 8bQCusS.jpg]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [VB.NET] Animated Form Extend [SRC] Fragma 6 5,228 10-10-2013, 12:18 PM
Last Post: Saket
  [VB.Net][SRC] YouTube Bot HF~Legend 5 3,373 11-25-2012, 05:54 AM
Last Post: Ixam
  [VB.Net][SRC]ProgressBar Color HF~Legend 14 6,802 09-08-2012, 04:18 PM
Last Post: spesificrelax
  [VB.NET] Basic Reverse Connection RAT [SRC] hasam 1 2,838 02-01-2012, 03:10 PM
Last Post: AceInfinity
  VB.NET Computer Information [SRC] Fragma 35 15,712 01-07-2012, 03:56 PM
Last Post: Quantum

Forum Jump:


Users browsing this thread: 1 Guest(s)