I'm trying to generate a huge random number in C++ using the GMP library but am having issues figuring out the syntax. This is slightly different from other examples I've found because I need to set a floor and ceiling for the random number to be between. This is kinda what I need to do:
mpz_class high, low;
low = pow(2,199);
high = pow(2,210);
// code to use the high and low numbers to generate the random number
I know this isn't much to go on, but again, I'm not sure what the syntax would even be at this point, I've tried several things but nothing I've found enables me to tell GMP to use a high and low range for the number generation.
Thoughts?
Function: void mpz_urandomb (mpz_t rop, gmp_randstate_t state, mp_bitcnt_t n)
Generate a uniformly distributed random integer in the range 0 to 2^n−1, inclusive
So, take 210 - 199, and use that as n, generate a random number and add the result to pow(2,199).
If you want something more granular than a power of 2 upper limit, this won't work for you. You could try the unsigned int sized random function using the same technique above:
— Function: unsigned long gmp_urandomm_ui (gmp_randstate_t state, unsigned long n)
Return a uniformly distributed random number in the range 0 to n-1, inclusive.
Here, you would find your granular range and use that for n. Then add the random number to your lower value. The limitation is n must be less than MAXUINT, usually 2^32 -1