Thread: Testing Random Number Generator

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    175

    Testing Random Number Generator

    Hello All,

    I have code that generates 32 bytes random numbers taking input as 32 bit value. i.e 2^32 possible inputs.

    Now I passed 1-2^32 numbers to generate the random number 2^32 random numbers. I believe random numbers should not be duplicated.

    How do I test to make sure that it is truely random and are not duplicated? Any idea.

    Currently, I directed the random number result to txt file and developed a perl script that will go tro' each random number and compares with all other results.

    Wondering is there any better method as the above method is very time consuimg.

    Thanks,

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    http://www.google.co.uk/search?q=tests+for+randomness
    Quick test, generate lots of data and see how well it zips. If it compresses at all, then it isn't random.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Banned
    Join Date
    Jun 2005
    Posts
    594
    if you have a limited sized number, eventually it will come
    up with the same number, and in a large enough
    section there will be a pattern, the only way is
    to seed it with different numbers at each run time.

    and that assuming that each run time is short enough
    to not reach the pattern in the run.

    there something else you could try, but i dont know if it legal
    code because i havent tested it so i wont mention it here,
    at least not till after i try it.

    P.S.
    it comming up with the same number doesnt make it
    any less random, beable to predict the next number
    make it less random.
    Last edited by ILoveVectors; 08-11-2005 at 10:43 AM.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    175
    Can I use WinZip to compress?

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    175
    Yes the seed is dynamic in nature.

  6. #6
    .
    Join Date
    Nov 2003
    Posts
    307
    Random numbers do repeat:

    Random number = all numbers over the given range are equally possible at every "draw" of a new number.

    [edit]
    PS: do not use your random number generator for cryptography.[/edit]

  7. #7
    Banned
    Join Date
    Jun 2005
    Posts
    594
    Quote Originally Posted by jim mcnamara
    [edit]
    PS: do not use your random number generator for cryptography.[/edit]
    unless of course you are allowing the user to generate themselves a key
    in which case it could be useful, as long as you display the key
    for them of course.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > Can I use WinZip to compress?
    Yes, any commonly available compress program will work.
    Save the binary data, not the text version.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random Number Generator Class
    By abachler in forum Windows Programming
    Replies: 4
    Last Post: 09-03-2008, 08:30 AM
  2. gsl seeding random number generator
    By sqytoad in forum C Programming
    Replies: 22
    Last Post: 06-24-2008, 02:29 PM
  3. Random number generator
    By rehan in forum C++ Programming
    Replies: 1
    Last Post: 02-25-2008, 02:14 AM
  4. Random number + guessing game trouble
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-08-2007, 03:33 AM
  5. random number generator
    By Verbenaca in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2005, 08:05 AM