• Log in or sign up for an account here: https://www.sythe.org/login

How to generate random numbers and letters (help)

w000t

Grand Master

$5 USD Donor New
Joined
Jan 23, 2007
Sythe Gold
0
Messages
2,608
Location
GFX section.
Well I've begun working on my first VB.net program its a password genorator all it does is generates a random sequence for a password and i cant seem to figure out how to get it to generate random numbers and letters. Any help is appreciated.
 
First implment this code in your form:
Code:
    Private Function RandomNumberAsString(ByVal Min As Int32, ByVal Max As Int32) As String
        Return (New Random).Next(Min, Max).ToString
    End Function

Then when a user clicks Button1 or whatever put this code for it.
Code:
TextBox1.Text = Me.RandomNumberAsString(1000, 999999)

This will randomly generate a number between 1000 and 999999, change it as needed.
 
Public Function Gen_Rand_Password(PassLength As Integer) As String

Dim RetVal As String

Dim Max As Integer

Dim Min As Integer

Max = 126

Min = 48

Randomize Timer


If PassLength < 8 Then

Gen_Rand_Password = "error: invalid length"

End If


For I = 1 To PassLength

RetVal = RetVal & Chr(Int((Max - Min + 1) * Rnd + Min))

Next I

Gen_Rand_Password = RetVal

End Function

RandomPassword = Gen_Rand_Password(8)

Code is set to the standard length of eight. Shoot me a PM if you're unable to apply.

If your not 100% with you "for loops" then look at this tutorial: http://www.youtube.com/watch?v=aM_5FWRk23c

It's fairly basic but you get the idea.
 
Runescape Gamblingrunescape gambling
Back
Top