Click or drag to resize
gmp_libmpz_random2 Method
Generate a random integer of at most max_size limbs, with long strings of zeros and ones in the binary representation.

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_random2(
	mpz_t rop,
	mp_size_t max_size
)

Parameters

rop
Type: Math.Gmp.Nativempz_t
The result integer.
max_size
Type: Math.Gmp.Nativemp_size_t
The maximum number of limbs.
Remarks

Useful for testing functions and algorithms, since this kind of random numbers have proven to be more likely to trigger corner-case bugs. Negative random numbers are generated when max_size is negative.

This function is obsolete. Use mpz_rrandomb instead.

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 set the value of rop to 0.
mpz_t rop = new mpz_t();
gmp_lib.mpz_init(rop);

// Generate a random integer.
gmp_lib.mpz_random(rop, 100);

// Free all memory occupied by rop.
gmp_lib.mpz_clear(rop);
See Also