/** * A random number is generated until a probable prime number is found. * * @see BigInteger#BigInteger(int,int,Random) * @see BigInteger#probablePrime(int,Random) * @see #isProbablePrime(BigInteger, int) */ internal static BigInteger consBigInteger(int bitLength, int certainty, java.util.Random rnd) { // PRE: bitLength >= 2; // For small numbers get a random prime from the prime table if (bitLength <= 10) { int[] rp = offsetPrimes[bitLength]; return BIprimes[rp[0] + rnd.nextInt(rp[1])]; } int shiftCount = (-bitLength) & 31; int last = (bitLength + 31) >> 5; BigInteger n = new BigInteger(1, last, new int[last]); last--; do {// To fill the array with random integers for (int i = 0; i < n.numberLength; i++) { n.digits[i] = rnd.nextInt(); } // To fix to the correct bitLength n.digits[last] = (int)((long)n.digits[last] | (long)(0x80000000)); n.digits[last] = java.dotnet.lang.Operator.shiftRightUnsignet(n.digits[last], shiftCount); // To create an odd number n.digits[0] |= 1; } while (!isProbablePrime(n, certainty)); return n; }