lundi 28 juin 2021

GMP random generator in C

I wanted to generate in do-while loop random number from range [1;10000000000000000000000]. I'm looking for simple and fast way.

I created

    #define n 10000000000000000000001
    
    mpz_init(n);
    
    gmp_randinit_mt(state);
    gmp_randseed_ui(state, 100000U);
    
    int main()
    {
    
   do{
    mpz_urandomm(r, state, n);
    
    gmp_printf("Number: %Zd\n",r)
    gmp_lib.gmp_randclear(state);
    gmp_lib.mpz_clears(r, n, null);
    
    }while(1)

}

I don't understand what should be state equal to. I've chosen mpz_urandomm() due to the end of range equal to n-1.




Aucun commentaire:

Enregistrer un commentaire