java.math
Class BigInteger

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.lang.Number sample code for java.lang.Number definition code for java.lang.Number 
      extended by java.math.BigInteger
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable , Comparable sample code for java.lang.Comparable definition code for java.lang.Comparable <BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger >

public class BigInteger
extends Number sample code for java.lang.Number definition code for java.lang.Number
implements Comparable sample code for java.lang.Comparable definition code for java.lang.Comparable <BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger >

Immutable arbitrary-precision integers. All operations behave as if BigIntegers were represented in two's-complement notation (like Java's primitive integer types). BigInteger provides analogues to all of Java's primitive integer operators, and all relevant methods from java.lang.Math. Additionally, BigInteger provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.

Semantics of arithmetic operations exactly mimic those of Java's integer arithmetic operators, as defined in The Java Language Specification. For example, division by zero throws an ArithmeticException, and division of a negative by a positive yields a negative (or zero) remainder. All of the details in the Spec concerning overflow are ignored, as BigIntegers are made as large as necessary to accommodate the results of an operation.

Semantics of shift operations extend those of Java's shift operators to allow for negative shift distances. A right-shift with a negative shift distance results in a left shift, and vice-versa. The unsigned right shift operator (>>>) is omitted, as this operation makes little sense in combination with the "infinite word size" abstraction provided by this class.

Semantics of bitwise logical operations exactly mimic those of Java's bitwise integer operators. The binary operators (and, or, xor) implicitly perform sign extension on the shorter of the two operands prior to performing the operation.

Comparison operations perform signed integer comparisons, analogous to those performed by Java's relational and equality operators.

Modular arithmetic operations are provided to compute residues, perform exponentiation, and compute multiplicative inverses. These methods always return a non-negative result, between 0 and (modulus - 1), inclusive.

Bit operations operate on a single bit of the two's-complement representation of their operand. If necessary, the operand is sign- extended so that it contains the designated bit. None of the single-bit operations can produce a BigInteger with a different sign from the BigInteger being operated on, as they affect only a single bit, and the "infinite word size" abstraction provided by this class ensures that there are infinitely many "virtual sign bits" preceding each BigInteger.

For the sake of brevity and clarity, pseudo-code is used throughout the descriptions of BigInteger methods. The pseudo-code expression (i + j) is shorthand for "a BigInteger whose value is that of the BigInteger i plus that of the BigInteger j." The pseudo-code expression (i == j) is shorthand for "true if and only if the BigInteger i represents the same value as the BigInteger j." Other pseudo-code expressions are interpreted similarly.

All methods and constructors in this class throw NullPointerException when passed a null object reference for any input parameter.

Since:
JDK1.1
See Also:
BigDecimal sample code for java.math.BigDecimal definition code for java.math.BigDecimal , Serialized Form

Field Summary
static BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger ONE sample code for java.math.BigInteger.ONE definition code for java.math.BigInteger.ONE
          The BigInteger constant one.
static BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger TEN sample code for java.math.BigInteger.TEN definition code for java.math.BigInteger.TEN
          The BigInteger constant ten.
static BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger ZERO sample code for java.math.BigInteger.ZERO definition code for java.math.BigInteger.ZERO
          The BigInteger constant zero.
 
Constructor Summary
BigInteger sample code for java.math.BigInteger.BigInteger(byte[]) definition code for java.math.BigInteger.BigInteger(byte[]) (byte[] val)
          Translates a byte array containing the two's-complement binary representation of a BigInteger into a BigInteger.
BigInteger sample code for java.math.BigInteger.BigInteger(int, byte[]) definition code for java.math.BigInteger.BigInteger(int, byte[]) (int signum, byte[] magnitude)
          Translates the sign-magnitude representation of a BigInteger into a BigInteger.
BigInteger sample code for java.math.BigInteger.BigInteger(int, int, java.util.Random) definition code for java.math.BigInteger.BigInteger(int, int, java.util.Random) (int bitLength, int certainty, Random sample code for java.util.Random definition code for java.util.Random  rnd)
          Constructs a randomly generated positive BigInteger that is probably prime, with the specified bitLength.
BigInteger sample code for java.math.BigInteger.BigInteger(int, java.util.Random) definition code for java.math.BigInteger.BigInteger(int, java.util.Random) (int numBits, Random sample code for java.util.Random definition code for java.util.Random  rnd)
          Constructs a randomly generated BigInteger, uniformly distributed over the range 0 to (2numBits - 1), inclusive.
BigInteger sample code for java.math.BigInteger.BigInteger(java.lang.String) definition code for java.math.BigInteger.BigInteger(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  val)
          Translates the decimal String representation of a BigInteger into a BigInteger.
BigInteger sample code for java.math.BigInteger.BigInteger(java.lang.String, int) definition code for java.math.BigInteger.BigInteger(java.lang.String, int) (String sample code for java.lang.String definition code for java.lang.String  val, int radix)
          Translates the String representation of a BigInteger in the specified radix into a BigInteger.
 
Method Summary
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger abs sample code for java.math.BigInteger.abs() definition code for java.math.BigInteger.abs() ()
          Returns a BigInteger whose value is the absolute value of this BigInteger.
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger add sample code for java.math.BigInteger.add(java.math.BigInteger) definition code for java.math.BigInteger.add(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  val)
          Returns a BigInteger whose value is (this + val).
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger and sample code for java.math.BigInteger.and(java.math.BigInteger) definition code for java.math.BigInteger.and(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  val)
          Returns a BigInteger whose value is (this & val).
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger andNot sample code for java.math.BigInteger.andNot(java.math.BigInteger) definition code for java.math.BigInteger.andNot(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  val)
          Returns a BigInteger whose value is (this & ~val).
 int bitCount sample code for java.math.BigInteger.bitCount() definition code for java.math.BigInteger.bitCount() ()
          Returns the number of bits in the two's complement representation of this BigInteger that differ from its sign bit.
 int bitLength sample code for java.math.BigInteger.bitLength() definition code for java.math.BigInteger.bitLength() ()
          Returns the number of bits in the minimal two's-complement representation of this BigInteger, excluding a sign bit.
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger clearBit sample code for java.math.BigInteger.clearBit(int) definition code for java.math.BigInteger.clearBit(int) (int n)
          Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit cleared.
 int compareTo sample code for java.math.BigInteger.compareTo(java.math.BigInteger) definition code for java.math.BigInteger.compareTo(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  val)
          Compares this BigInteger with the specified BigInteger.
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger divide sample code for java.math.BigInteger.divide(java.math.BigInteger) definition code for java.math.BigInteger.divide(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  val)
          Returns a BigInteger whose value is (this / val).
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger [] divideAndRemainder sample code for java.math.BigInteger.divideAndRemainder(java.math.BigInteger) definition code for java.math.BigInteger.divideAndRemainder(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  val)
          Returns an array of two BigIntegers containing (this / val) followed by (this % val).
 double doubleValue sample code for java.math.BigInteger.doubleValue() definition code for java.math.BigInteger.doubleValue() ()
          Converts this BigInteger to a double.
 boolean equals sample code for java.math.BigInteger.equals(java.lang.Object) definition code for java.math.BigInteger.equals(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  x)
          Compares this BigInteger with the specified Object for equality.
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger flipBit sample code for java.math.BigInteger.flipBit(int) definition code for java.math.BigInteger.flipBit(int) (int n)
          Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit flipped.
 float floatValue sample code for java.math.BigInteger.floatValue() definition code for java.math.BigInteger.floatValue() ()
          Converts this BigInteger to a float.
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger gcd sample code for java.math.BigInteger.gcd(java.math.BigInteger) definition code for java.math.BigInteger.gcd(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  val)
          Returns a BigInteger whose value is the greatest common divisor of abs(this) and abs(val).
 int getLowestSetBit sample code for java.math.BigInteger.getLowestSetBit() definition code for java.math.BigInteger.getLowestSetBit() ()
          Returns the index of the rightmost (lowest-order) one bit in this BigInteger (the number of zero bits to the right of the rightmost one bit).
 int hashCode sample code for java.math.BigInteger.hashCode() definition code for java.math.BigInteger.hashCode() ()
          Returns the hash code for this BigInteger.
 int intValue sample code for java.math.BigInteger.intValue() definition code for java.math.BigInteger.intValue() ()
          Converts this BigInteger to an int.
 boolean isProbablePrime sample code for java.math.BigInteger.isProbablePrime(int) definition code for java.math.BigInteger.isProbablePrime(int) (int certainty)
          Returns true if this BigInteger is probably prime, false if it's definitely composite.
 long longValue sample code for java.math.BigInteger.longValue() definition code for java.math.BigInteger.longValue() ()
          Converts this BigInteger to a long.
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger max sample code for java.math.BigInteger.max(java.math.BigInteger) definition code for java.math.BigInteger.max(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  val)
          Returns the maximum of this BigInteger and val.
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger min sample code for java.math.BigInteger.min(java.math.BigInteger) definition code for java.math.BigInteger.min(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  val)
          Returns the minimum of this BigInteger and val.
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger mod sample code for java.math.BigInteger.mod(java.math.BigInteger) definition code for java.math.BigInteger.mod(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  m)
          Returns a BigInteger whose value is (this mod m).
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger modInverse sample code for java.math.BigInteger.modInverse(java.math.BigInteger) definition code for java.math.BigInteger.modInverse(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  m)
          Returns a BigInteger whose value is (this-1 mod m).
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger modPow sample code for java.math.BigInteger.modPow(java.math.BigInteger, java.math.BigInteger) definition code for java.math.BigInteger.modPow(java.math.BigInteger, java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  exponent, BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  m)
          Returns a BigInteger whose value is (thisexponent mod m).
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger multiply sample code for java.math.BigInteger.multiply(java.math.BigInteger) definition code for java.math.BigInteger.multiply(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  val)
          Returns a BigInteger whose value is (this * val).
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger negate sample code for java.math.BigInteger.negate() definition code for java.math.BigInteger.negate() ()
          Returns a BigInteger whose value is (-this).
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger nextProbablePrime sample code for java.math.BigInteger.nextProbablePrime() definition code for java.math.BigInteger.nextProbablePrime() ()
          Returns the first integer greater than this BigInteger that is probably prime.
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger not sample code for java.math.BigInteger.not() definition code for java.math.BigInteger.not() ()
          Returns a BigInteger whose value is (~this).
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger or sample code for java.math.BigInteger.or(java.math.BigInteger) definition code for java.math.BigInteger.or(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  val)
          Returns a BigInteger whose value is (this | val).
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger pow sample code for java.math.BigInteger.pow(int) definition code for java.math.BigInteger.pow(int) (int exponent)
          Returns a BigInteger whose value is (thisexponent).
static BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger probablePrime sample code for java.math.BigInteger.probablePrime(int, java.util.Random) definition code for java.math.BigInteger.probablePrime(int, java.util.Random) (int bitLength, Random sample code for java.util.Random definition code for java.util.Random  rnd)
          Returns a positive BigInteger that is probably prime, with the specified bitLength.
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger remainder sample code for java.math.BigInteger.remainder(java.math.BigInteger) definition code for java.math.BigInteger.remainder(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  val)
          Returns a BigInteger whose value is (this % val).
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger setBit sample code for java.math.BigInteger.setBit(int) definition code for java.math.BigInteger.setBit(int) (int n)
          Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit set.
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger shiftLeft sample code for java.math.BigInteger.shiftLeft(int) definition code for java.math.BigInteger.shiftLeft(int) (int n)
          Returns a BigInteger whose value is (this << n).
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger shiftRight sample code for java.math.BigInteger.shiftRight(int) definition code for java.math.BigInteger.shiftRight(int) (int n)
          Returns a BigInteger whose value is (this >> n).
 int signum sample code for java.math.BigInteger.signum() definition code for java.math.BigInteger.signum() ()
          Returns the signum function of this BigInteger.
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger subtract sample code for java.math.BigInteger.subtract(java.math.BigInteger) definition code for java.math.BigInteger.subtract(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  val)
          Returns a BigInteger whose value is (this - val).
 boolean testBit sample code for java.math.BigInteger.testBit(int) definition code for java.math.BigInteger.testBit(int) (int n)
          Returns true if and only if the designated bit is set.
 byte[] toByteArray sample code for java.math.BigInteger.toByteArray() definition code for java.math.BigInteger.toByteArray() ()
          Returns a byte array containing the two's-complement representation of this BigInteger.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.math.BigInteger.toString() definition code for java.math.BigInteger.toString() ()
          Returns the decimal String representation of this BigInteger.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.math.BigInteger.toString(int) definition code for java.math.BigInteger.toString(int) (int radix)
          Returns the String representation of this BigInteger in the given radix.
static BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger valueOf sample code for java.math.BigInteger.valueOf(long) definition code for java.math.BigInteger.valueOf(long) (long val)
          Returns a BigInteger whose value is equal to that of the specified long.
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger xor sample code for java.math.BigInteger.xor(java.math.BigInteger) definition code for java.math.BigInteger.xor(java.math.BigInteger) (BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  val)
          Returns a BigInteger whose value is (this ^ val).
 
Methods inherited from class java.lang.Number sample code for java.lang.Number definition code for java.lang.Number
byteValue sample code for java.lang.Number.byteValue() definition code for java.lang.Number.byteValue() , shortValue sample code for java.lang.Number.shortValue() definition code for java.lang.Number.shortValue()
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

ZERO sample code for java.math.BigInteger.ZERO

public static final BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  ZERO
The BigInteger constant zero.

Since:
1.2

ONE sample code for java.math.BigInteger.ONE

public static final BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  ONE
The BigInteger constant one.

Since:
1.2

TEN sample code for java.math.BigInteger.TEN

public static final BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  TEN
The BigInteger constant ten.

Since:
1.5
Constructor Detail

BigInteger sample code for java.math.BigInteger(byte[]) definition code for java.math.BigInteger(byte[])

public BigInteger(byte[] val)
Translates a byte array containing the two's-complement binary representation of a BigInteger into a BigInteger. The input array is assumed to be in big-endian byte-order: the most significant byte is in the zeroth element.

Parameters:
val - big-endian two's-complement binary representation of BigInteger.
Throws:
NumberFormatException sample code for java.lang.NumberFormatException definition code for java.lang.NumberFormatException - val is zero bytes long.

BigInteger sample code for java.math.BigInteger(int, byte[]) definition code for java.math.BigInteger(int, byte[])

public BigInteger(int signum,
                  byte[] magnitude)
Translates the sign-magnitude representation of a BigInteger into a BigInteger. The sign is represented as an integer signum value: -1 for negative, 0 for zero, or 1 for positive. The magnitude is a byte array in big-endian byte-order: the most significant byte is in the zeroth element. A zero-length magnitude array is permissible, and will result inin a BigInteger value of 0, whether signum is -1, 0 or 1.

Parameters:
signum - signum of the number (-1 for negative, 0 for zero, 1 for positive).
magnitude - big-endian binary representation of the magnitude of the number.
Throws:
NumberFormatException sample code for java.lang.NumberFormatException definition code for java.lang.NumberFormatException - signum is not one of the three legal values (-1, 0, and 1), or signum is 0 and magnitude contains one or more non-zero bytes.

BigInteger sample code for java.math.BigInteger(java.lang.String, int) definition code for java.math.BigInteger(java.lang.String, int)

public BigInteger(String sample code for java.lang.String definition code for java.lang.String  val,
                  int radix)
Translates the String representation of a BigInteger in the specified radix into a BigInteger. The String representation consists of an optional minus sign followed by a sequence of one or more digits in the specified radix. The character-to-digit mapping is provided by Character.digit. The String may not contain any extraneous characters (whitespace, for example).

Parameters:
val - String representation of BigInteger.
radix - radix to be used in interpreting val.
Throws:
NumberFormatException sample code for java.lang.NumberFormatException definition code for java.lang.NumberFormatException - val is not a valid representation of a BigInteger in the specified radix, or radix is outside the range from Character.MIN_RADIX sample code for java.lang.Character.MIN_RADIX definition code for java.lang.Character.MIN_RADIX to Character.MAX_RADIX sample code for java.lang.Character.MAX_RADIX definition code for java.lang.Character.MAX_RADIX , inclusive.
See Also:
Character.digit(char, int) sample code for java.lang.Character.digit(char, int) definition code for java.lang.Character.digit(char, int)

BigInteger sample code for java.math.BigInteger(java.lang.String) definition code for java.math.BigInteger(java.lang.String)

public BigInteger(String sample code for java.lang.String definition code for java.lang.String  val)
Translates the decimal String representation of a BigInteger into a BigInteger. The String representation consists of an optional minus sign followed by a sequence of one or more decimal digits. The character-to-digit mapping is provided by Character.digit. The String may not contain any extraneous characters (whitespace, for example).

Parameters:
val - decimal String representation of BigInteger.
Throws:
NumberFormatException sample code for java.lang.NumberFormatException definition code for java.lang.NumberFormatException - val is not a valid representation of a BigInteger.
See Also:
Character.digit(char, int) sample code for java.lang.Character.digit(char, int) definition code for java.lang.Character.digit(char, int)

BigInteger sample code for java.math.BigInteger(int, java.util.Random) definition code for java.math.BigInteger(int, java.util.Random)

public BigInteger(int numBits,
                  Random sample code for java.util.Random definition code for java.util.Random  rnd)
Constructs a randomly generated BigInteger, uniformly distributed over the range 0 to (2numBits - 1), inclusive. The uniformity of the distribution assumes that a fair source of random bits is provided in rnd. Note that this constructor always constructs a non-negative BigInteger.

Parameters:
numBits - maximum bitLength of the new BigInteger.
rnd - source of randomness to be used in computing the new BigInteger.
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - numBits is negative.
See Also:
bitLength sample code for java.math.BigInteger.bitLength definition code for java.math.BigInteger.bitLength

BigInteger sample code for java.math.BigInteger(int, int, java.util.Random) definition code for java.math.BigInteger(int, int, java.util.Random)

public BigInteger(int bitLength,
                  int certainty,
                  Random sample code for java.util.Random definition code for java.util.Random  rnd)
Constructs a randomly generated positive BigInteger that is probably prime, with the specified bitLength.

It is recommended that the probablePrime sample code for java.math.BigInteger.probablePrime(int, java.util.Random) definition code for java.math.BigInteger.probablePrime(int, java.util.Random) method be used in preference to this constructor unless there is a compelling need to specify a certainty.

Parameters:
bitLength - bitLength of the returned BigInteger.
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 - 1/2certainty). The execution time of this constructor is proportional to the value of this parameter.
rnd - source of random bits used to select candidates to be tested for primality.
Throws:
ArithmeticException sample code for java.lang.ArithmeticException definition code for java.lang.ArithmeticException - bitLength < 2.
See Also:
bitLength sample code for java.math.BigInteger.bitLength definition code for java.math.BigInteger.bitLength
Method Detail

probablePrime sample code for java.math.BigInteger.probablePrime(int, java.util.Random) definition code for java.math.BigInteger.probablePrime(int, java.util.Random)

public static BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  probablePrime(int bitLength,
                                       Random sample code for java.util.Random definition code for java.util.Random  rnd)
Returns a positive BigInteger that is probably prime, with the specified bitLength. The probability that a BigInteger returned by this method is composite does not exceed 2-100.

Parameters:
bitLength - bitLength of the returned BigInteger.
rnd - source of random bits used to select candidates to be tested for primality.
Returns:
a BigInteger of bitLength bits that is probably prime
Throws:
ArithmeticException sample code for java.lang.ArithmeticException definition code for java.lang.ArithmeticException - bitLength < 2.
See Also:
bitLength sample code for java.math.BigInteger.bitLength