gmp_lib.gmp_randseed Method

GMP Native Interface for .NET

gmp_libgmp_randseed Method
Set an initial seed value into state.

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_randseed(
	gmp_randstate_t state,
	mpz_t seed
)
Public Shared Sub gmp_randseed ( 
	state As gmp_randstate_t,
	seed As mpz_t
)
public:
static void gmp_randseed(
	gmp_randstate_t^ state, 
	mpz_t^ seed
)
static member gmp_randseed : 
        state : gmp_randstate_t * 
        seed : mpz_t -> unit 

Parameters

state
Type: Math.Gmp.Nativegmp_randstate_t
The state to seed.
seed
Type: Math.Gmp.Nativempz_t
The seed.
Remarks

The size of a seed determines how many different sequences of random numbers that it’s possible to generate. The “quality” of the seed is the randomness of a given seed compared to the previous seed used, and this affects the randomness of separate number sequences. The method for choosing a seed is critical if the generated numbers are to be used for important applications, such as generating cryptographic keys.

Traditionally the system time has been used to seed, but care needs to be taken with this. If an application seeds often and the resolution of the system clock is low, then the same sequence of numbers might be repeated. Also, the system time is quite easy to guess, so if unpredictability is required then it should definitely not be the only source for the seed value. On some systems there’s a special device /dev/random which provides random data better suited for use as a seed.

Examples
// Create new random number generator state, and initialize state with the Mersenne Twister algorithm.
gmp_randstate_t state = new gmp_randstate_t();
gmp_lib.gmp_randinit_mt(state);

// Seed random number generator.
mpz_t seed = new mpz_t();
gmp_lib.mpz_init_set_ui(seed, 100000U);
gmp_lib.gmp_randseed(state, seed);

// Free all memory occupied by state and seed.
gmp_lib.gmp_randclear(state);
gmp_lib.mpz_clear(seed);
' Create new random number generator state, and initialize state with the Mersenne Twister algorithm.
Dim state As New gmp_randstate_t()

gmp_lib.gmp_randinit_mt(state)

' Seed random number generator.
Dim seed As New mpz_t()

gmp_lib.mpz_init_set_ui(seed, 100000UI)
gmp_lib.gmp_randseed(state, seed)

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

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