Forum Moderators: open
codecharacters = 35
Array("a","b","c","d","e","f","g","h","i","j","k","l", _
"m","n","o","p","q","r","s","t","u","v","w","x", _
"y","z","1","2","3","4","5","6","7","8","9")
FOR x = 1 TO 5
RANDOMIZE()
thiscode = (Int(((codecharacters - 1) * Rnd) + 1))
function RandomString(intLength)
Randomize()
dim strPattern, intDiff, i, strReturn
strPattern = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"
intDiff = len(strPattern) - 1
for i = 1 to intLength
strReturn = strReturn & Mid(strPattern, Round((rnd()*intDiff)+1),1)
next
RandomString = strReturn
end function
For non-critical purposes, mattglett's code will work well, but call Randomize() only once per script (not inside the function as mattglett has done) otherwise the random numbers will become easily predectable (especially on fast/repetitive calls to the function).
[edited by: mrMister at 3:33 am (utc) on Nov. 20, 2006]
... but call Randomize() only once per script (not inside the function as mattglett has done) otherwise the random numbers will become easily predectable ...
agreed.
placing Randomize() inside procedures (esp looping procedures) will produce a lot of duplicates. Structure your generator in such a way that Randomize() is only called once per page load.