random numbers !

delta trinity deltatrinity@hotmail.com
Wed, 18 Dec 2002 16:14:20 -0500

>   So, I expect, that each time, I'll run the programm, I'll get some
>   new numbers.. because they are chosen randomly.. but it's not the
>   case, and I always get the same.
>That's how things are supposed to work.  All computer random
>number generators work like that--i.e., they are psuedo random.
>To change the sequence of psuedo random numbers, you need to
>seed the generators.  Please see the GMP manual for details
>on how to do that.

If you start from default seed, you'll get the same results over and over.  
In fact, computer can't create really 'random' numbers.  That's why we call 
those functios 'pseudo-random'.  It look like series of random numbers but 
in fact, the way it work, is that at each call, the computer take the 
preceeding results and compute a new number from it.  Then, it put the 
result into the seed for use in the next function call.

If you want a new series of numbers to be generated on each run of your 
program, you need to feed it with a different seed each time.  The easiest 
way to do this is to take the system clock (possibly down to the 
milliseconds) and feed this to the seed once at the beginning of your 
program (see gmp_randseed in section 9).

The useness of this function depend mostly on what you want to do.  If you 
want to generate pseudo-random numbers for anything that it isn't security 
related, that's fine.  If you want to use this for cryptographic pourpous, 
then this may not be secure enough.  For that, you would probably need to 
take more that the system clock.

I saw somewhere a program that displayed a box on the screen over which you 
pass the mouse cursor for a few seconds.  The algorithm took the actual 
points of the box over which you mouse cursor pass to generate the seed.  
This is more secure as there no *probable* way of plotting the same pattern 

For strong cryptographic porpous, the best way would be to use an hardware 
random number generator.  Those are built with a diode as a noise source.  0 
and 1 are derived from that noise.  Seed is feed from the result.

Add photos to your e-mail with MSN 8. Get 2 months FREE*.