Hi,
I wanna generate a random alphanumeric in the following format:
d4g2o5m3-u1q2-s7z9-z6o8-o3q2c2m5m2s9
So with your help, I wrote a public function like this:
However, sometimes the call to this function will return the same result, I mean it's not completely random?
How that's possible?
Thank you
I wanna generate a random alphanumeric in the following format:
d4g2o5m3-u1q2-s7z9-z6o8-o3q2c2m5m2s9
So with your help, I wrote a public function like this:
Visual Basic:
Public Function GenerateContactID() As String
Dim MyRandom As New Random
GenerateContactID = Nothing
For MyLoop As Integer = 1 To 8
If MyLoop Mod 2 = 1 Then
GenerateContactID = GenerateContactID + Convert.ToChar(MyRandom.Next(97, 123))
End If
If MyLoop Mod 2 = 0 Then
GenerateContactID = GenerateContactID + MyRandom.Next(1, 10).ToString
End If
Next
GenerateContactID = GenerateContactID + "-"
For MyLoop As Integer = 1 To 4
If MyLoop Mod 2 = 1 Then
GenerateContactID = GenerateContactID + Convert.ToChar(MyRandom.Next(97, 123))
End If
If MyLoop Mod 2 = 0 Then
GenerateContactID = GenerateContactID + MyRandom.Next(1, 10).ToString
End If
Next
GenerateContactID = GenerateContactID + "-"
For MyLoop As Integer = 1 To 4
If MyLoop Mod 2 = 1 Then
GenerateContactID = GenerateContactID + Convert.ToChar(MyRandom.Next(97, 123))
End If
If MyLoop Mod 2 = 0 Then
GenerateContactID = GenerateContactID + MyRandom.Next(1, 10).ToString
End If
Next
GenerateContactID = GenerateContactID + "-"
For MyLoop As Integer = 1 To 4
If MyLoop Mod 2 = 1 Then
GenerateContactID = GenerateContactID + Convert.ToChar(MyRandom.Next(97, 123))
End If
If MyLoop Mod 2 = 0 Then
GenerateContactID = GenerateContactID + MyRandom.Next(1, 10).ToString
End If
Next
GenerateContactID = GenerateContactID + "-"
For MyLoop As Integer = 1 To 12
If MyLoop Mod 2 = 1 Then
GenerateContactID = GenerateContactID + Convert.ToChar(MyRandom.Next(97, 123))
End If
If MyLoop Mod 2 = 0 Then
GenerateContactID = GenerateContactID + MyRandom.Next(1, 10).ToString
End If
Next
End Function
How that's possible?
Thank you
Last edited: