Random String

K

Kent

What am I missing here. Why doesn't this produce a random string. It is
kind of random.

<%
Const ConstantLower = "bcdfghjklmnpqrstvwxyz"
Const VowelLower = "aeiou"
Const Numbers = "0123456789"
Const NumOfChar = 12

Dim x : x = 0
Dim TmpVal
Dim TmpName


Dim y
y = 0

Do while y < 100
x = 1
TmpName = ""
TmpVal=""
Do while x <= NumOfChar
randomize
TmpVal = int(Rnd*3)
select case TmpVal
Case 0
randomize
TmpVal = int(Rnd*21)
if TmpVal = 0 then TmpVal = 1
TmpName = TmpName & mid
(ConstantLower,TmpVal,1)
Case 1
randomize
TmpVal = int(Rnd*5)
if TmpVal = 0 then TmpVal = 1
TmpName = TmpName & mid
(VowelLower,TmpVal,1)
Case 2
randomize
TmpVal = int(Rnd*10)
if TmpVal = 0 then TmpVal = 1
TmpName = TmpName & mid
(Numbers,TmpVal,1)
end Select
x = x + 1
loop

Response.Write TmpName & "<BR>"
y = y + 1
Loop
%>



Thanks for your help,
Kent
 
R

Ray Costanzo [MVP]

What do you see? I got this output:

amcigsr110ac<BR>
e170j60q106e<BR>
eah0leob2oe8<BR>
paannj2e6px0<BR>
ivmo50bo72il<BR>
i71ar06yoa0w<BR>
vqq6txfj8di1<BR>
xka7758t0813<BR>
a0vh86kaaoy7<BR>
caeibea2ai5f<BR>
dy8a0gnsamci<BR>
gsr110ace170<BR>
j60q106eeah0<BR>
mioc3oe8iaap<BR>
pk3e6qy0ixna<BR>
rdc873ino81e<BR>
s07b8e0owis7<BR>
vyhl0fo2omex<BR>
8s0v0823a1wj<BR>
b6l1a0b7daii<BR>
ce022i6aga0a<BR>
0hqtanaiavih<BR>
1bade280k7fr<BR>
20teeaj1mioc<BR>
s07h833ooir7<BR>
coal0ao2oeef<BR>
fs0o0gp6amda<BR>
g6l1a0acaaii<BR>
je0q2i6agaha<BR>
lhqt2naiabin<BR>
42ade480e7mr<BR>
50b4eaj3mioa<BR>
6o48iaappk5e<BR>
6qfkidearkc7<BR>
75imo81es07h<BR>
04loo6t7daam<BR>
0ao2ae3ggi0o<BR>
0hq6apfej7e2<BR>
10adaaioke1r<BR>
2otaaak1mjrv<BR>
3qaiad7p4kea<BR>
e580e8nsr0c5<BR>
i3lnniaa6o40<BR>
6a0iqe647rhl<BR>
ifiaima88sip<BR>
o02ev17j04lo<BR>
iep5yodhocsa<BR>
wja0bp7i0c35<BR>
x20f0ihaaoob<BR>
aaei1ea4ar5c<BR>
cxfahdmqalbe<BR>
f8i331aba368<BR>
h6243oxeeag2<BR>
jeooeiaoebom<BR>
lg4a5m0gpbkw<BR>
n2yi64eki7aa<BR>
50i0oa1tiep5<BR>
boaj8ai1xka0<BR>
cr8i0fm5al0a<BR>
16kaaoobaaei<BR>
heapai5fdyga<BR>
kgnr2mcigbi3<BR>
31ace470j63q<BR>
40beeah3leoa<BR>
5oe8eaanmh4e<BR>
6pdhicmop2bo<BR>
75ili70ar06f<BR>
oa2woiq6boaj<BR>
h3apai5leog0<BR>
jeoy2ikenbi3<BR>
311a3478p63w<BR>
40yeeae3ieoa<BR>
5oe8ej0ttp4e<BR>
6vdhicsow2a7<BR>
75isi702y06f<BR>
7a2ooix6boei<BR>
8ei1ora0cx8i<BR>
0dm5al0e16qa<BR>
08oba14ih3ap<BR>
166eeah0leob<BR>
2oe5pbin422e<BR>
3480i7mo50b4<BR>
eai3iioaro48<BR>
ia0wvq5e6xfj<BR>
6doaxka775it<BR>
o813b0vh832o<BR>
oiy7coei0eo2<BR>
oiefdy8o0gn6<BR>
w28k04na07vx<BR>
f0ee0ao3ai4j<BR>
ao081jr7aqge<BR>
k7e220aaa3io<BR>
mi1t3owaaal1<BR>
pesw4raief7r<BR>
ql3aes00e8pv<BR>
s1a653epq6aa<BR>
7a506a1iiet5<BR>
8ijmohiaina0<BR>
yt7iob24w28k<BR>
05pa07oya0ei<BR>

Ray at work
 
G

Gottfried Mayer

Kent said:
What am I missing here. Why doesn't this produce a random string. It is
kind of random.

<%
Const ConstantLower = "bcdfghjklmnpqrstvwxyz"
Const VowelLower = "aeiou"
Const Numbers = "0123456789"
Const NumOfChar = 12

Dim x : x = 0
Dim TmpVal
Dim TmpName


Dim y
y = 0

Do while y < 100
x = 1
TmpName = ""
TmpVal=""
Do while x <= NumOfChar
randomize
TmpVal = int(Rnd*3)
select case TmpVal
Case 0
randomize
TmpVal = int(Rnd*21)
if TmpVal = 0 then TmpVal = 1
TmpName = TmpName & mid
(ConstantLower,TmpVal,1)
Case 1
randomize
TmpVal = int(Rnd*5)
if TmpVal = 0 then TmpVal = 1
TmpName = TmpName & mid
(VowelLower,TmpVal,1)
Case 2
randomize
TmpVal = int(Rnd*10)
if TmpVal = 0 then TmpVal = 1
TmpName = TmpName & mid
(Numbers,TmpVal,1)
end Select
x = x + 1
loop

Response.Write TmpName & "<BR>"
y = y + 1
Loop
%>



Thanks for your help,
Kent

Hi Kent,

The rnd function only creates quasi-random numbers:

I have seen this while playing around with a random password generator I
created.
You can try this yourself:
create strings with a length of 128 or 256 or 512 ..., then you'll see
that a number of times the exact same string will be created.
Example (with my randomPW.asp using the rnd function):

Fixed length (128 chars) Passwords:
6kD6qnbw6EJS68rjbPr6S25u3f54c7UrRS0D3uU6f1V8482s3UKN3e0B8CgrPN308VD4PKp4L0dF24L10wMl6NsJKYs0iUQoO0R0PpQKrAkr4OJ7G1d6XpSC01ksl7WN
6kD6qnbw6EJS68rjbPr6S25u3f54c7UrRS0D3uU6f1V8482s3UKN3e0B8CgrPN308VD4PKp4L0dF24L10wMl6NsJKYs0iUQoO0R0PpQKrAkr4OJ7G1d6XpSC01ksl7WN
6kD6qnbw6EJS68rjbPr6S25u3f54c7UrRS0D3uU6f1V8482s3UKN3e0B8CgrPN308VD4PKp4L0dF24L10wMl6NsJKYs0iUQoO0R0PpQKrAkr4OJ7G1d6XpSC01ksl7WN
6kD6qnbw6EJS68rjbPr6S25u3f54c7UrRS0D3uU6f1V8482s3UKN3e0B8CgrPN308VD4PKp4L0dF24L10wMl6NsJKYs0iUQoO0R0PpQKrAkr4OJ7G1d6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kAHMCB77x06AclO1r1jMS7c7i4F8iYC3UOnr403XIAuga3bl3
3WeVJQXrONETsAMfJ0N8jp4YkBt155e3R1q48kuE34GFJ5EhA2VywadwI8xN87UL223a0lrQ8205am3kAHMCB77x06AclO1r1jMS7c7i4F8iYC3UOnr403XIAuga3bl3
3WeVJQXrONETsAMfJ0N8jp4YkBt155e3R1q48kuE34GFJ5EhA2VywadwI8xN87UL223a0lrQ8205am3kAHMCB77x06AclO1r1jMS7c7i4F8iYC3UOnr403XIAuga3bl3
3WeVJQXrONETsAMfJ0N8jp4YkBt155e3R1q48kuE34GFJ5EhA2VywadwI8xN87UL223a0lrQ8205am3kAHMCB77x06AclO1r1jMS7c7i4F8iYC3UOnr403XIAuga3bl3
3WeVJQXrONETsAMfJ0N8jp4YkBt155e3R1q48kuE34GFJ5EhA2VywadwI8xN87UL223a0lrQ8205am3kAHMCB77x06AclO1r1jMS7c7i4F8iYC3UOnr403XIAuga3bl3
3WeVJQXrONETsAMfJ0N8jp4YkBt155e3R1q48kuE34GFJ5EhA2VywadwI8xN87UL223a0lrQ8205am3kAHMCB77x06AclO1r1jMS7c7i4F8iYC3UOnr403XIAuga3bl3
3WeVJQXrONETsAMfJ0N8jp4YkBt155e3R1q48kuE34GFJ5EhA2VywadwI8xN87UL223a0lrQ8205am3kAHMCB77x06AclO1r1jMS7c7i4F8iYC3UOnr403XIAuga3bl3
811Scv20MFXevtTeT4JBD1yuPI8Gff03WqKU6h44V3vBo06FatmN62860J81QDCJA8Xuwb580jmXhQhho08CY6YrlkV0go6No28yTK0OE4FC3xQQ6maybAJbXR8MhTj1
811Scv20MFXevtTeT4JBD1yuPI8Gff03WqKU6h44V3vBo06FatmN62860J81QDCJA8Xuwb580jmXhQhho08CY6YrlkV0go6No28yTK0OE4FC3xQQ6maybAJbXR8MhTj1

But as I will never create 128 character passwords (the users can't even
remember 8 chars), this issue is very minor to me.


Just my 2 cents

Gottfried
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top