Why does Java BigInteger say 'probably prime' and not 'certainly prime'?











up vote
0
down vote

favorite












The JavaDoc of BigInteger makes me feel very insecure, for example the following constructor says:



BigInteger(int bitLength, int certainty, Random rnd)



Constructs a randomly generated positive BigInteger that is probably
prime, with the specified bitLength.




Why only probably? Why not certainly? Can I still trust that the result would be a prime number?










share|improve this question




















  • 1




    Did you read the detailed section? The increasing runtime is why only probably. See also stackoverflow.com/q/8744085/3001761
    – jonrsharpe
    Nov 10 at 20:39








  • 2




    It's only probably because it uses a prime testing algorithm that may fail. The rest of the documentation provides an upper bound on the probability of failure.
    – James K Polk
    Nov 10 at 20:40






  • 1




    There is an algorithm due to Maurer that find primes that are guaranteed to be prime. See for example this problem. This algorithm is not currently available in the Java runtime.
    – James K Polk
    Nov 10 at 21:03















up vote
0
down vote

favorite












The JavaDoc of BigInteger makes me feel very insecure, for example the following constructor says:



BigInteger(int bitLength, int certainty, Random rnd)



Constructs a randomly generated positive BigInteger that is probably
prime, with the specified bitLength.




Why only probably? Why not certainly? Can I still trust that the result would be a prime number?










share|improve this question




















  • 1




    Did you read the detailed section? The increasing runtime is why only probably. See also stackoverflow.com/q/8744085/3001761
    – jonrsharpe
    Nov 10 at 20:39








  • 2




    It's only probably because it uses a prime testing algorithm that may fail. The rest of the documentation provides an upper bound on the probability of failure.
    – James K Polk
    Nov 10 at 20:40






  • 1




    There is an algorithm due to Maurer that find primes that are guaranteed to be prime. See for example this problem. This algorithm is not currently available in the Java runtime.
    – James K Polk
    Nov 10 at 21:03













up vote
0
down vote

favorite









up vote
0
down vote

favorite











The JavaDoc of BigInteger makes me feel very insecure, for example the following constructor says:



BigInteger(int bitLength, int certainty, Random rnd)



Constructs a randomly generated positive BigInteger that is probably
prime, with the specified bitLength.




Why only probably? Why not certainly? Can I still trust that the result would be a prime number?










share|improve this question















The JavaDoc of BigInteger makes me feel very insecure, for example the following constructor says:



BigInteger(int bitLength, int certainty, Random rnd)



Constructs a randomly generated positive BigInteger that is probably
prime, with the specified bitLength.




Why only probably? Why not certainly? Can I still trust that the result would be a prime number?







java biginteger






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 22:08









Rudy Velthuis

23.8k43474




23.8k43474










asked Nov 10 at 20:29









Long Nguyen

919




919








  • 1




    Did you read the detailed section? The increasing runtime is why only probably. See also stackoverflow.com/q/8744085/3001761
    – jonrsharpe
    Nov 10 at 20:39








  • 2




    It's only probably because it uses a prime testing algorithm that may fail. The rest of the documentation provides an upper bound on the probability of failure.
    – James K Polk
    Nov 10 at 20:40






  • 1




    There is an algorithm due to Maurer that find primes that are guaranteed to be prime. See for example this problem. This algorithm is not currently available in the Java runtime.
    – James K Polk
    Nov 10 at 21:03














  • 1




    Did you read the detailed section? The increasing runtime is why only probably. See also stackoverflow.com/q/8744085/3001761
    – jonrsharpe
    Nov 10 at 20:39








  • 2




    It's only probably because it uses a prime testing algorithm that may fail. The rest of the documentation provides an upper bound on the probability of failure.
    – James K Polk
    Nov 10 at 20:40






  • 1




    There is an algorithm due to Maurer that find primes that are guaranteed to be prime. See for example this problem. This algorithm is not currently available in the Java runtime.
    – James K Polk
    Nov 10 at 21:03








1




1




Did you read the detailed section? The increasing runtime is why only probably. See also stackoverflow.com/q/8744085/3001761
– jonrsharpe
Nov 10 at 20:39






Did you read the detailed section? The increasing runtime is why only probably. See also stackoverflow.com/q/8744085/3001761
– jonrsharpe
Nov 10 at 20:39






2




2




It's only probably because it uses a prime testing algorithm that may fail. The rest of the documentation provides an upper bound on the probability of failure.
– James K Polk
Nov 10 at 20:40




It's only probably because it uses a prime testing algorithm that may fail. The rest of the documentation provides an upper bound on the probability of failure.
– James K Polk
Nov 10 at 20:40




1




1




There is an algorithm due to Maurer that find primes that are guaranteed to be prime. See for example this problem. This algorithm is not currently available in the Java runtime.
– James K Polk
Nov 10 at 21:03




There is an algorithm due to Maurer that find primes that are guaranteed to be prime. See for example this problem. This algorithm is not currently available in the Java runtime.
– James K Polk
Nov 10 at 21:03












2 Answers
2






active

oldest

votes

















up vote
4
down vote



accepted










From the docs for BigInteger(int bitLength, int certainty, Random rnd):




certainty: a measure of the uncertainty that the caller is
willing to tolerate. The probability that the new BigInteger
represents a prime number will exceed
(1 - ½certainty). The execution time of
this constructor is proportional to the value of this parameter.




So the constructor lets you specify the certainty that it will be prime, which is why the docs say "probably"






share|improve this answer






























    up vote
    4
    down vote













    Because the probabilistic algorithm runs a lot faster than verifying that the number is definitely prime.






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243130%2fwhy-does-java-biginteger-say-probably-prime-and-not-certainly-prime%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      4
      down vote



      accepted










      From the docs for BigInteger(int bitLength, int certainty, Random rnd):




      certainty: a measure of the uncertainty that the caller is
      willing to tolerate. The probability that the new BigInteger
      represents a prime number will exceed
      (1 - ½certainty). The execution time of
      this constructor is proportional to the value of this parameter.




      So the constructor lets you specify the certainty that it will be prime, which is why the docs say "probably"






      share|improve this answer



























        up vote
        4
        down vote



        accepted










        From the docs for BigInteger(int bitLength, int certainty, Random rnd):




        certainty: a measure of the uncertainty that the caller is
        willing to tolerate. The probability that the new BigInteger
        represents a prime number will exceed
        (1 - ½certainty). The execution time of
        this constructor is proportional to the value of this parameter.




        So the constructor lets you specify the certainty that it will be prime, which is why the docs say "probably"






        share|improve this answer

























          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






          From the docs for BigInteger(int bitLength, int certainty, Random rnd):




          certainty: a measure of the uncertainty that the caller is
          willing to tolerate. The probability that the new BigInteger
          represents a prime number will exceed
          (1 - ½certainty). The execution time of
          this constructor is proportional to the value of this parameter.




          So the constructor lets you specify the certainty that it will be prime, which is why the docs say "probably"






          share|improve this answer














          From the docs for BigInteger(int bitLength, int certainty, Random rnd):




          certainty: a measure of the uncertainty that the caller is
          willing to tolerate. The probability that the new BigInteger
          represents a prime number will exceed
          (1 - ½certainty). The execution time of
          this constructor is proportional to the value of this parameter.




          So the constructor lets you specify the certainty that it will be prime, which is why the docs say "probably"







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 10 at 20:41









          James K Polk

          29.2k106694




          29.2k106694










          answered Nov 10 at 20:39









          GBlodgett

          7,14541329




          7,14541329
























              up vote
              4
              down vote













              Because the probabilistic algorithm runs a lot faster than verifying that the number is definitely prime.






              share|improve this answer

























                up vote
                4
                down vote













                Because the probabilistic algorithm runs a lot faster than verifying that the number is definitely prime.






                share|improve this answer























                  up vote
                  4
                  down vote










                  up vote
                  4
                  down vote









                  Because the probabilistic algorithm runs a lot faster than verifying that the number is definitely prime.






                  share|improve this answer












                  Because the probabilistic algorithm runs a lot faster than verifying that the number is definitely prime.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 10 at 20:40









                  OpenSauce

                  7,05311628




                  7,05311628






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243130%2fwhy-does-java-biginteger-say-probably-prime-and-not-certainly-prime%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      The Sandy Post

                      Danny Elfman

                      Pages that link to "Head v. Amoskeag Manufacturing Co."