Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27069

Random strings...

$
0
0
Currently using this
Code:

    Public Shared Function generateRandomString(ByVal length As Integer)
        Dim _allowedChars As String = "0123456789"
        Dim randomNumber As New Random()
        Dim chars(length - 1) As Char
        Dim allowedCharCount As Integer = _allowedChars.Length
        For i As Integer = 0 To length - 1
            chars(i) = _allowedChars.Chars(CInt(Fix((_allowedChars.Length) * randomNumber.NextDouble())))
        Next i
        Return New String(chars)
    End Function

Code:

        Dim loginID_PART_1 As String = getMisc().generateRandomString(3)
        Dim loginID_PART_2 As String = getMisc().generateRandomString(3)
        Dim loginID_PART_3 As String = getMisc().generateRandomString(3)


And when printed, each part is the same.. i.e. 505-505-505, when they should be different.

What's going on?

Viewing all articles
Browse latest Browse all 27069

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>