Thread: Problems with Random Numbers

  1. #1
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003

    Problems with Random Numbers

    Problem: "random" function rand() is showing patterns in my password-generating program (go to to see the 1000-password list). To seed rand(), I use the current time. Every time a new password is made, re-seed rand() with the current time. However, there are some patterns:

    The likelyhood of a password being repeated in that list is (aprox.) 0.04% (the same password was repeated 4 times): this doesn't bother much

    The likelyhood of a 4-letter pattern (BHOU/bhou) being repeated in the list is (aprox.) 5.3%: this bothers me.

    3-letter pattern (CIO/cio): aprox. 7.8%

    Are patterns in the time (like the same numbers -- such as seconds) causing patterns in the passwords?

    P.S.: I think that there should be 281,474,976,710,656 possiblities, with 8 characters per password and 64 possible characters.
    01011001 01101111 01110101 00100000 01110100 01101111 01101111 1101011 00100000 01110100 01101000 01101001 01110011 00100000 01101101 01110101 01100011 01101000 00100000 01110100 01101000 01101101 01100101 00100000 01110100 01101111 00100000 01110010 01100101 01100001 01100100 00100000 01011001 01101000 01101001 01110011 00111111 00100000 01000100 01100001 01101101 01101110 00100001 00000000

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    >> Every time a new password is made, re-seed rand() with the current time.
    Don't do that and see what you get.


  3. #3
    The C-er
    Join Date
    Mar 2004
    Yes, Codeplug has a point.

    The algorithm for random number generation produce a series of pseudo random numbers, with each one being derived from the previous one, or more precisely from the previous internal state of the random number "engine".

    The algorithm is designed to work effectively with these values, not from externally seeded values.

    There have been cases (although I can't quote my sources) where random values used as seeds for more random values also show patterns developing, where intuitively you might expect it to be just as random.

    BTW kinghajj, did you spot the spelling mistake in your signature?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doubts regarding random numbers generation
    By girish1026 in forum C Programming
    Replies: 9
    Last Post: 12-31-2008, 10:47 PM
  2. random numbers
    By mesmer in forum C Programming
    Replies: 4
    Last Post: 10-24-2008, 01:22 PM
  3. Generating a sequence of numbers in a random order
    By mirbogat in forum C Programming
    Replies: 15
    Last Post: 08-12-2008, 02:01 PM
  4. Generating 100k to 1 million unique random numbers
    By Ariod in forum C Programming
    Replies: 4
    Last Post: 08-26-2005, 12:59 PM
  5. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 05:51 PM