Jump to content
Tuts 4 You

generate random 10 chars


grizzmo

Recommended Posts

Hi,

I was looking to generate unlimited 10 chars random numbers in vb.net. I found that it is not possible to set a variable to a certain lenght in the new vb.net, acoording a lot of coding sites. When I thought it worked it also started generating 8 and 9 chars of lenght. So, after a little while I came up with this:

Imports System.TextPublic Class Form1    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        Dim startIndex As New String("1234567890")
Dim random As New Random
Dim startIndex1 As New String("0987654321")
Dim random1 As New Random
startIndex = random.Next(startIndex)
startIndex1 = random1.Next(startIndex1)
Dim str1 As String = startIndex
Dim str2 As String = startIndex1
Dim str3 As String = (str1 + str2).Substring(0, 10)
TextBox2.Text = str3
End Sub
End Class

This makes 2 strings str1 and str2, concentate them (str3)and take with Substring(0, 10) the wanted chars exact(10) all the time without exceptions. This is also a lot faster then generating with only 1 startIndex.

Btw: I want be spamming the shoutbox, ....... I am banned. I guess I deserved this.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...