Whenever this code is executed, it gives the same result. I am not able to get a random value.
The value of temp always comes out as 6400306986398558324. (lambda = 256.)
mpz_t group_size,temp;
mpz_init(group_size);
mpz_init(temp);
gmp_randstate_t state;
gmp_randinit_mt (state);
mpz_urandomb (temp, state,lambda);
mpz_nextprime (group_size, temp);
printf("temp : %ld \n",mpz_get_ui(temp));
printf("Group Size : %ld \n",mpz_get_ui(group_size));
You need to set a seed for the state. From official documentation:
Function:
void gmp_randseed (gmp_randstate_t state, const mpz_t seed)
Function:
void gmp_randseed_ui (gmp_randstate_t state, unsigned long int seed)
Here is example for your code (not really useful in real world as time(NULL)
will return the same result for one whole second).
...
gmp_randinit_mt (state);
gmp_randseed_ui(state, time(NULL))
mpz_urandomb (temp, state,lambda);
...