Click or drag to resize
gmp_libgmp_randinit_lc_2exp Method
Initialize state with a linear congruential algorithm X = (aX + c) mod 2^m2exp.

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 gmp_randinit_lc_2exp(
	gmp_randstate_t state,
	mpz_t a,
	uint c,
	mp_bitcnt_t m2exp
)

Parameters

state
Type: Math.Gmp.Nativegmp_randstate_t
The state to initialize.
a
Type: Math.Gmp.Nativempz_t
Parameter of the algorithm.
c
Type: SystemUInt32
Parameter of the algorithm.
m2exp
Type: Math.Gmp.Nativemp_bitcnt_t
Parameter of the algorithm.
Remarks

The low bits of X in this algorithm are not very random. The least significant bit will have a period no more than 2, and the second bit no more than 4, etc. For this reason only the high half of each X is actually used.

When a random number of more than m2exp / 2 bits is to be generated, multiple iterations of the recurrence are used and the results concatenated.

Examples
// Create new random number generator state.
gmp_randstate_t state = new gmp_randstate_t();

// Initialize state with a linear congruential random number generator algorithm.
mpz_t a = new mpz_t();
gmp_lib.mpz_init_set_ui(a, 100000U);
gmp_lib.gmp_randinit_lc_2exp(state, a, 13, 300);

// Free all memory occupied by state and a.
gmp_lib.gmp_randclear(state);
gmp_lib.mpz_clear(a);
See Also