Willmage
10 pts. | 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
46810 pts. | 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.






