Random number generation

5 pts.
Tags:
Random Number Generator
SQL
SQL Server
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..

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hello,
hereafter an example code:

<pre>
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
</pre>

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • willmage
    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!
    20 pointsBadges:
    report
  • Denny Cherry
    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.
    66,070 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following