我在 vb.net 中有一个这样的随机函数,它返回这样的 6 位字母数字字符串。
Public Function rand() As String
Dim rng As Random = New Random
Dim sb As New StringBuilder
' Selection of pure numbers sequence or mixed one
Dim pureNumbers = rng.Next(1, 11)
If pureNumbers < 7 Then
' Generate a sequence of only digits
Dim number As Integer = rng.Next(1, 1000000)
Dim digits As String = number.ToString("000000")
For i As Integer = 1 To 6
Dim idx As Integer = rng.Next(0, digits.Length)
sb.Append(digits.Substring(idx, 1))
Next
Else
' Generate a sequence of digits and letters
Dim s As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
For i As Integer = 1 To 6
Dim idx As Integer = rng.Next(0, 36)
sb.Append(s.Substring(idx, 1))
Next
End If
Return sb.ToString()
End Function
问题是当它返回时0
or O
or 1
orI
等等{"1", "I", "O", "0", "5", "S", "7"}
我想用'A'替换这些字符,然后应该返回最终的随机字符串。