Random String

Discussion in 'ASP General' started by Kent, Oct 27, 2005.

  1. Kent

    Kent Guest

    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
    Kent, Oct 27, 2005
    #1
    1. Advertising

  2. 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

    "Kent" <> wrote in message
    news:...
    > 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
    >
    Ray Costanzo [MVP], Oct 28, 2005
    #2
    1. Advertising

  3. Kent wrote:
    > 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
    6kD6qnbw6EJS68rjbPr6S25u3f54c7UrRS0D3uU6f1V8482s3UKN3e0B8CgrPN308VD4PKp4L0dF24L10wMl6NsJKYs0iUQoO0R0PpQKrAkr4OJ7G1d6XpSC01ksl7WN
    6kD6qnbw6EJS68rjbPr6S25u3f54c7UrRS0D3uU6f1V8482s3UKN3e0B8CgrPN308VD4PKp4L0dF24L10wMl6NsJKYs0iUQoO0R0PpQKrAkr4OJ7G1d6XpSC01ksl7WN
    6kD6qnbw6EJS68rjbPr6S25u3f54c7UrRS0D3uU6f1V8482s3UKN3e0B8CgrPN308VD4PKp4L0dF24L10wMl6NsJKYs0iUQoO0R0PpQKrAkr4OJ7G1d6XpSC01ksl7WN
    6kD6qnbw6EJS68rjbPr6S25u3f54c7UrRS0D3uU6f1V8482s3UKN3e0B8CgrPN308VD4PKp4L0dF24L10wMl6NsJKYs0iUQoO0R0PpQKrAkr4OJ7G1d6XpSC01ksl7WN
    6kD6qnbw6EJS68rjbPr6S25u3f54c7UrRS0D3uU6f1V8482s3UKN3e0B8CgrPN308VD4PKp4L0dF24L10wMl6NsJKYs0iUQoO0R0PpQKrAkr4OJ7G1d6XpSC01ksl7WN
    6kD6qnbw6EJS68rjbPr6S25u3f54c7UrRS0D3uU6f1V8482s3UKN3e0B8CgrPN308VD4PKp4L0dF24L10wMl6NsJKYs0iUQoO0R0PpQKrAkr4OJ7G1d6XpSC01ksl7WN
    6kD6qnbw6EJS68rjbPr6S25u3f54c7UrRS0D3uU6f1V8482s3UKN3e0B8CgrPN308VD4PKp4L0dF24L10wMl6NsJKYs0iUQoO0R0PpQKrAkr4OJ7G1d6XpSC01ksl7WN
    3WeVJQXrONETsAMfJ0N8jp4YkBt155e3R1q48kuE34GFJ5EhA2VywadwI8xN87UL223a0lrQ8205am3kAHMCB77x06AclO1r1jMS7c7i4F8iYC3UOnr403XIAuga3bl3
    3WeVJQXrONETsAMfJ0N8jp4YkBt155e3R1q48kuE34GFJ5EhA2VywadwI8xN87UL223a0lrQ8205am3kAHMCB77x06AclO1r1jMS7c7i4F8iYC3UOnr403XIAuga3bl3
    3WeVJQXrONETsAMfJ0N8jp4YkBt155e3R1q48kuE34GFJ5EhA2VywadwI8xN87UL223a0lrQ8205am3kAHMCB77x06AclO1r1jMS7c7i4F8iYC3UOnr403XIAuga3bl3
    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
    Gottfried Mayer, Oct 28, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darren Clark

    Random NOt random?

    Darren Clark, Jun 24, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    443
    mikeb
    Jun 24, 2004
  2. Maziar Aflatoun

    Random not really random...

    Maziar Aflatoun, Aug 4, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    26,666
    Maziar Aflatoun
    Aug 5, 2004
  3. Lars-Erik Aabech
    Replies:
    8
    Views:
    824
    Lars-Erik Aabech
    Apr 28, 2005
  4. globalrev
    Replies:
    4
    Views:
    744
    Gabriel Genellina
    Apr 20, 2008
  5. VK
    Replies:
    15
    Views:
    1,125
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page