Random number generation
For eg, if my input number is 123456, the result should be a4y2d365p1. some combination of characters with the original 6 digit numbers.
Please do let me know if this could be done by any ways..
Dim numbers
Dim letters
Dim ID
Randomize
numbers="0123456789"
letters="abcdefghijklmnopqrstuvwxyz"
for i=1 to 10
if i mod 2 <> 0 Then
ID = ID & mid(letters,Int((26*Rnd) +1),1)
Else
ID = ID & mid(numbers,Int((10*Rnd) +1),1)
end If
Next
wscript.echo ID
Looking for relevant SQL Server Whitepapers? Visit the SearchSQLServer.com Research Library.
Willmage | May 19 2008 5:29PM GMT
The above answer will give you a random letter/number output, but it doesn’t take into account the original number the user started with. Here is an answer I have for this question:
Dim Letters, OrigNum
Dim TextNum, ID, TempHold
Dim RandNum, FinalAns
Letters = “abcdefghijklmnopqrstuvwxyz”
OrigNum = 123456
Randomize
Rem ** the following randomizes the original number
RandNum = “”
TextNum = Trim(Str(OrigNum))
For i = 1 To 5
ID = Int((Len(TextNum) * Rnd) + 1)
RandNum = RandNum & Mid(TextNum, ID, 1)
TempHold = Left(TextNum, ID - 1)
TempHold = TempHold & Mid(TextNum, ID + 1, Len(TextNum) - ID)
TextNum = TempHold
Next
RandNum = RandNum & TextNum
Rem ** the following creates your new random character/number string
FinalAns = “”
For i = 1 To 10
If Len(FinalAns) + Len(RandNum) = 10 Then
FinalAns = FinalAns & Left(RandNum, 1)
RandNum = Right(RandNum, Len(RandNum) - 1)
Else
If Len(RandNum) = 0 Then
FinalAns = FinalAns & Mid(Letters, Int(26 * Rnd) + 1, 1)
Else
If ((Int(Rnd * 2) + 1) Mod 2) <> 0 Then
FinalAns = FinalAns & Left(RandNum, 1)
RandNum = Right(RandNum, Len(RandNum) - 1)
Else
FinalAns = FinalAns & Mid(Letters, Int(26 * Rnd) + 1, 1)
End If
End If
End If
Next
Hope that helps!
Mrdenny | May 20 2008 12:30AM GMT
I’m curious, what’s the purpose behind this code?
Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.