private BigInteger RandomPrimeMSBSet(int bits) { if (bits <= 1) { throw new ArithmeticException("No primes with this bitcount"); } BigInteger limit = ((BigInteger)1) << bits; while (true) { var p = this.NextProbablePrime(BigIntegerHelper.SetBit(BigIntegerHelper.RandomIntBits(bits - 1), bits - 1)); if (p < limit) { return(p); } } }