gmp_lib.mpz_rrandomb Method

GMP Native Interface for .NET

gmp_libmpz_rrandomb Method
Generate a random integer 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_rrandomb(
	mpz_t rop,
	gmp_randstate_t state,
	mp_bitcnt_t n
)
Public Shared Sub mpz_rrandomb ( 
	rop As mpz_t,
	state As gmp_randstate_t,
	n As mp_bitcnt_t
)
public:
static void mpz_rrandomb(
	mpz_t^ rop, 
	gmp_randstate_t^ state, 
	mp_bitcnt_t n
)
static member mpz_rrandomb : 
        rop : mpz_t * 
        state : gmp_randstate_t * 
        n : mp_bitcnt_t -> unit 

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.Nativemp_bitcnt_t
The operand integer.
Remarks

Useful for testing functions and algorithms, since this kind of random numbers have proven to be more likely to trigger corner-case bugs. The random number will be in the range 2^(n - 1) to 2^n - 1, inclusive.

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);

// Generate a random integer in the range [2^(50-1), (2^50)-1].
gmp_lib.mpz_rrandomb(rop, state, 50);

// Free all memory occupied by state and rop.
gmp_lib.gmp_randclear(state);
gmp_lib.mpz_clear(rop);
' Create, initialize, and seed a new random number generator.
Dim state As New gmp_randstate_t()
gmp_lib.gmp_randinit_mt(state)
gmp_lib.gmp_randseed_ui(state, 100000UI)

' Create, initialize, and set the value of rop to 0.
Dim rop As New mpz_t()
gmp_lib.mpz_init(rop)

' Generate a random integer in the range [2^(50-1), (2^50)-1].
gmp_lib.mpz_rrandomb(rop, state, 50)

' Free all memory occupied by state and rop.
gmp_lib.gmp_randclear(state)
gmp_lib.mpz_clear(rop)

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

See Also