Random number generation
5 pts.
0
Q:
Random number generation
Hi, I have a 6 digit number. I need to make this as a 10 characters with those 6 digits within it.
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..
ASKED: May 18 2008  6:44 PM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
Hello,
hereafter an example code:


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
Last Answered: May 19 2008  6:45 AM GMT by Alessandro.panzetta   9615 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

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.

 
0