Click or drag to resize
gmp_libmpz_urandomm Method
Generate a uniform random integer in the range 0 to n - 1, inclusive.

Namespace:  Math.Gmp.Native
Assembly:  Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static void mpz_urandomm(
	mpz_t rop,
	gmp_randstate_t state,
	mpz_t n
)

Parameters

rop
Type: Math.Gmp.Nativempz_t
The result integer.
state
Type: Math.Gmp.Nativegmp_randstate_t
The random number generator state.
n
Type: Math.Gmp.Nativempz_t
The operand integer.
Remarks

The variable state must be initialized by calling one of the gmp_randinit functions (GNU MP - Random State Initialization) before invoking this function.

The random number functions of GMP come in two groups; older function that rely on a global state, and newer functions that accept a state parameter that is read and modified. Please see the GNU MP - Random Number Functions for more information on how to use and not to use random number functions.

Examples
// Create, initialize, and seed a new random number generator.
gmp_randstate_t state = new gmp_randstate_t();
gmp_lib.gmp_randinit_mt(state);
gmp_lib.gmp_randseed_ui(state, 100000U);

// Create, initialize, and set the value of rop to 0.
mpz_t rop = new mpz_t();
gmp_lib.mpz_init(rop);

// Create, initialize, and set a large integer.
mpz_t n = new mpz_t();
char_ptr value = new char_ptr("123 456 789 012 345 678 901");
gmp_lib.mpz_init_set_str(n, value, 10);

// Generate a random integer in the range [0, n-1].
gmp_lib.mpz_urandomm(rop, state, n);

// Free all memory occupied by state, rop, and n.
gmp_lib.gmp_randclear(state);
gmp_lib.mpz_clears(rop, n, null);
See Also