Testing Random Number Generator

This is a discussion on Testing Random Number Generator within the C Programming forums, part of the General Programming Boards category; Hello All, I have code that generates 32 bytes random numbers taking input as 32 bit value. i.e 2^32 possible ...

  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
    32,847
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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 11: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
    32,847
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 09:30 AM
  2. gsl seeding random number generator
    By sqytoad in forum C Programming
    Replies: 22
    Last Post: 06-24-2008, 03: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, 04:33 AM
  5. random number generator
    By Verbenaca in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2005, 09:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21