C
Crirus
Is there a function that return some random ID like string alphanumeric?
Like this:
A35sDsd1dSGsH
Thanks
Crirus
Like this:
A35sDsd1dSGsH
Thanks
Crirus
Is there a function that return some random ID like string alphanumeric?
Like this:
A35sDsd1dSGsH
Thanks
Crirus
Mick said:What's that CInt("0"c)? doesn't work here although Asc("0"c) does, as
does Asc("0").
What's that Machine.Shift.Left? doesn't work here. I understand what
it's meant to do though.(number between 0 and &HFFFFFFFF).
I like that Random class, hadn't seen that before, but, according to
the documentation, for best performance Random should only be created
once. StringBuilder.Append is faster than String +=.
You missed the LCase characters.
My much simpler version of that same function, with default time based
seeding of Random:
Private r As New Random
'I think 255 characters should be enough, although there's no reason
that 'you can't use Integer or Short instead of Byte, and have more.
Private Function RandomString(ByVal Stringlength As Byte) As String
Dim s As String = _
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Dim sb As New System.Text.StringBuilder
Do
sb.Append(s.Chars(r.Next(0, 61)))
Loop While sb.Length < Stringlength
Return sb.ToString
End Function
My version generated 100000 * 255character strings in 4 secs as
opposed to yours (updated to use stringbuilder and default seeding
for comparison) taking 6 secs(making the Random object a Class level
Private object reduced this to 5 secs). Without Stringbuilder yours
took 23 secs and 21 secs.
Before that Random Class I used the old Rnd function and the fastest
I could get, even using Stringbuilder, was 28 secs.
So I learned something useful Today.
Thankyou
Mick Doherty
One Handed Man said:What version of .NET framework are you using