Exemplo n.º 1
0
        public static MPZ URandom(MPZ max, bool inclusive = false)
        {
            MPZ result = new MPZ();

            if (inclusive)
            {
                mpz_t tmp = new mpz_t();
                gmp_lib.mpz_init(tmp);
                gmp_lib.mpz_add_ui(tmp, max.Value, 1U);
                gmp_lib.mpz_urandomm(result.Value, MPZ.RandomState.Value, tmp);
                gmp_lib.mpz_clear(tmp);
            }
            else
            {
                gmp_lib.mpz_urandomm(result.Value, MPZ.RandomState.Value, max.Value);
            }

            return(result);
        }
Exemplo n.º 2
0
 public RandState(mpz_t value)
 {
     gmp_lib.gmp_randinit_default(Value);
     gmp_lib.mpz_init_set(Seed, value);
     gmp_lib.gmp_randseed(Value, Seed);
 }