Hi,
Any pointer to generate a long 20 digit random number or string?
Help greatly appreciated.
Hi,
Any pointer to generate a long 20 digit random number or string?
Help greatly appreciated.
Is this correct?
Dim r As New Random
Dim i As Integer
Dim ii As string
genNum.Text = “4”
For count as integer = 0 to 14
i = r.inrange(0, 9)
genNum.AppendText str(i)
next
a variation:
Dim Randomizer As New Random
Dim i As Integer
Dim BigNumberTextField As String
SeedField.Text = “4”
For count As Integer = 0 To 19
i = Randomizer.inrange(0, 9)
BigNumberTextField = BigNumberTextField + Str(i)
Next
MsgBox(BigNumberTextField)
If you just want a random Integer:
[code]Protected Function getRandomNumWAD(tempInt1 As Integer, tempInt2 As Integer) as Integer
Dim r As New Random
Return r.InRange(tempInt1, tempInt2)
End Function
[/code]
If you want other types of random stuff as well:
[code]Protected Function getRandomPasswordWAD(Type As String, tempLength As Integer, randomLength As Boolean = False) as String
Dim tempChoice, tempReturn As String 'tempString
Dim tempInt, tempInt2 As Integer
Dim r As New Random
select case Type
case “Hex”
tempChoice = “0123456789ABCDEF”
case “Letters”
tempChoice = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”
case “Numbers”
tempChoice = “0123456789”
case “Symbols”
tempChoice = “!#$%&()*+,-./:;<=>?@[]^_`{|}~”
case “Serial Letters and Numbers”
tempChoice = “abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789” 'no I or O or L or 1 or 0
case “Letters and Numbers”
tempChoice = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789”
case “Letters and Symbols”
tempChoice = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&()*+,-./:;<=>?@[]^_`{|}~”
case “Numbers and Symbols”
tempChoice = “0123456789!#$%&()*+,-./:;<=>?@[]^_`{|}~”
case “Letters, Numbers and Symbols”
tempChoice = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&()*+,-./:;<=>?@[]^_`{|}~”
case “Serial Letters”
tempChoice = “ABCDEFGHJKLMNPQRSTUVWXYZ” 'no I or O
case else
tempChoice = Type
end select
if randomLength then tempLength = r.InRange(6, max(6, tempLength))
tempInt2 = len(tempChoice)
for tempInt = 1 to tempLength
tempReturn = tempReturn + mid(tempChoice, r.InRange(1, tempInt2), 1)
next
Return tempReturn
End Function
[/code]
Note that Random is not cryptographically secure. If you need that, follow Wayne’s suggestion.