GMP Native Interface for .NET
gmp_libmpz_millerrabin Method |
An implementation of the probabilistic primality test found in Knuth's Seminumerical Algorithms book.
Namespace: Math.Gmp.Native
Assembly: Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)

public static int mpz_millerrabin( mpz_t n, int reps )
Public Shared Function mpz_millerrabin ( n As mpz_t, reps As Integer ) As Integer
public: static int mpz_millerrabin( mpz_t^ n, int reps )
static member mpz_millerrabin : n : mpz_t * reps : int -> int
Parameters
- n
- Type: Math.Gmp.Nativempz_t
The operand integer. - reps
- Type: SystemInt32
The number of internal passes of the probabilistic algorithm.
Return Value
Type: Int32If the function mpz_millerrabin returns 0 then n is not prime. If it returns 1, then n is 'probably' prime.

The probability of a false positive is (1/4)^reps, where reps is the number of internal passes of the probabilistic algorithm. Knuth indicates that 25 passes are reasonable.

// Create, initialize, and set the value of n to 12. mpz_t n = new mpz_t(); gmp_lib.mpz_init_set_ui(n, 12U); // Assert that n is a composite number. Assert.IsTrue(gmp_lib.mpz_millerrabin(n, 25) == 0); // Release unmanaged memory allocated for n. gmp_lib.mpz_clear(n);
' Create, initialize, and set the value of n to 12. Dim n As New mpz_t() gmp_lib.mpz_init_set_ui(n, 12UI) ' Assert that n is a composite number. Assert.IsTrue(gmp_lib.mpz_millerrabin(n, 25) = 0) ' Release unmanaged memory allocated for n. gmp_lib.mpz_clear(n)
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.
