randomize mpn_random

Paul Zimmermann Paul.Zimmermann at loria.fr
Mon Oct 30 21:40:24 CET 2006


> Anybody knows how to "randomize" the mpn_random? Every time my program starts it generates the same sequence of "random" numbers.
> 
> I know about high-level functions (gmp_randseed, gmp_randseed_ui) but I can't use them with low-level function mpn_random because there is no parameter of gmp_randstate_t type.

I suggest you have a look at mpn/generic/random.c and gmp-impl.h:

mpn/generic/random.c:
  rands = RANDS;
  _gmp_rand (ptr, rands, size * GMP_NUMB_BITS);

gmp-impl.h:
/* __gmp_rands is the global state for the old-style random functions, and     
   is also used in the test programs (hence the __GMP_DECLSPEC).               
                                                                               
   There's no seeding here, so mpz_random etc will generate the same           
   sequence every time.  This is not unlike the C library random functions     
   if you don't seed them, so perhaps it's acceptable.  Digging up a seed      
   from /dev/random or the like would work on many systems, but might          
   encourage a false confidence, since it'd be pretty much impossible to do    
   something that would work reliably everywhere.  In any case the new style   
   functions are recommended to applications which care about randomness, so   
   the old functions aren't too important.  */

Paul Zimmermann





More information about the gmp-discuss mailing list