示例#1
0
		/// <summary>
		/// Generates a random positive BigInteger with the specified number of bits and is possibly prime.
		/// </summary>
		/// <param name="bits">The bits.</param>
		/// <param name="confidence">The confidence.</param>
		/// <param name="rand">The rand.</param>
		/// <returns></returns>
		public static BigInteger genPseudoPrime(int bits, int confidence, Random rand)
		{
			BigInteger result = new BigInteger();
			bool done = false;

			while (!done)
			{
				result.genRandomBits(bits, rand);
				result.data[0] |= 0x01;		// make it odd

				// prime test
				done = result.isProbablePrime(confidence);
			}
			return result;
		}