How to generate different random numbers?

Pedro Gimeno Fortea parigalo at
Wed Feb 1 10:58:26 CET 2006

On 02/01/2006 09:06:20 AM, Forum Joiner wrote:

> I have this code:
>   // We generate the state
>   gmp_randinit_default ( state_1 );
>    // We generate the random number
>    mpz_urandomb (random_n, state, 10);
> The generated numbers are always the same. I don't know how to set  
> the seed.

Look up gmp_randseed and gmp_randseed_ui in the manual (and please look  
better next time before asking). You'll need a way of generating a  
different seed each time; that's not the library's responsibility as  
it's highly system- or application-dependent.

> I know how to generate numbers from 1 to 2^10, but how to get numbers
> only in the 2^9 ... 2^10 interval?

Just add 2^9 to a number with a maximum of (2^10-2^9). Do the math  

Note that this list is not the proper place to ask such basic questions  
which are actually not GMP-related. Consider asking for help in a  
different forum or mailing list.

-- Pedro Gimeno

More information about the gmp-discuss mailing list