Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Random String Generator for VBScript

1,421 views
Skip to first unread message

Lucas

unread,
Jul 9, 2002, 4:25:55 PM7/9/02
to
This is a little script I typed up to generate a random string in
VBScript. The intent was to use the string as an encryption password.
As is, it will not generate a string under 15 characters or over
thirty, but that can be easily modified.

Any comments/suggestions are appreciated.

Lucas

dim a, b
a=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")
b=Array(-1,1,0)
dim randstring

Function RandomNumber(intHighestNumber)
Randomize
RandomNumber = Int(Rnd * intHighestNumber) + 1
End Function


randomloopnum = RandomNumber(30)
Do While randomloopnum < 15
randomloopnum = RandomNumber(30)
Loop
icount = 0
Do While icount < randomloopnum
randomnumnum = RandomNumber(2)
if b(randomnumnum) = 1 then
randstring = randstring & RandomNumber(99)
elseif b(randomnumnum) = 0 then
randomarrnum = RandomNumber(25)

randomarraystuff = a(randomarrnum)

randomarrupper = RandomNumber(2)
randomarrupperi = b(randomarrupper)
if randomarrupperi = 0 then
randstring = randstring & UCase(randomarraystuff)
elseif randomarrupperi = 1 then
randstring = randstring & randomarraystuff
end if
end if
icount = icount+1
Loop

Response.Write randstring

Sarder Hasnut

unread,
Jul 9, 2002, 5:13:30 PM7/9/02
to
with your randstring, you now want to use encryption/ D..tion
http://www.aspin.com/func/content?tree=aspin/tutorial/variable/strings&i
d=2303410

can use it for that reson.


S. A. Hasnut
MCSD, CIW A
It Magnet
http://itmagnet.com.au


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

mK

unread,
Jul 10, 2002, 3:34:11 AM7/10/02
to
Why not make use of the rest of ascii character set?
It might be better to encapsulate the algorithm in a function that accepts
the length of the randomised string and returns the randomised string.
'-------------------------------


Option Explicit
MsgBox GetRandomString( 15)


Function GetRandomString( strLength)
const ascLbound = 32 ' 0 to 31 are nonprintable
const ascUbound = 127 'ASCII character set is the same as the first 128
characters
Dim i, sRandom

Randomize()
sRandom = ""
For i = 1 to strLength
sRandom = sRandom & Chr(( ascUbound - ascLbound + 1) * Rnd +
ascLbound)
Next
GetRandomString = sRandom
End Function

0 new messages