PHP Doku:: Check if number is "probably prime" - function.gmp-prob-prime.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzMathematische ErweiterungenGNU Multiple PrecisionGMP Funktionengmp_prob_prime

Ein Service von Reinhard Neidl - Webprogrammierung.

GMP Funktionen

<<gmp_powm

gmp_random>>

gmp_prob_prime

(PHP 4 >= 4.0.4, PHP 5)

gmp_prob_primeCheck if number is "probably prime"

Beschreibung

int gmp_prob_prime ( resource $a [, int $reps = 10 ] )

The function uses Miller-Rabin's probabilistic test to check if a number is a prime.

Parameter-Liste

a

The number being checked as a prime.

Dies kann entweder eine resource für einen GMP-Wert sein oder ein numerischer String, wenn es möglich ist, diesen in einen GMP-Wert umzuwandeln.

reps

Reasonable values of reps vary from 5 to 10 (default being 10); a higher value lowers the probability for a non-prime to pass as a "probable" prime.

Dies kann entweder eine resource für einen GMP-Wert sein oder ein numerischer String, wenn es möglich ist, diesen in einen GMP-Wert umzuwandeln.

Rückgabewerte

If this function returns 0, a is definitely not prime. If it returns 1, then a is "probably" prime. If it returns 2, then a is surely prime.

Beispiele

Beispiel #1 gmp_prob_prime() example

<?php
// definitely not a prime
echo gmp_prob_prime("6") . "\n";

// probably a prime
echo gmp_prob_prime("1111111111111111111") . "\n";

// definitely a prime
echo gmp_prob_prime("11") . "\n";
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

0
1
2


Keine BenutzerBeiträge.
- Beiträge aktualisieren...



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)