def generate_probable_prime(**kwargs):
 exact_bits = kwargs.pop('exact_bits', None)
 randfunc = kwargs.pop('randfunc', None)
 prime_filter = kwargs.pop('prime_filter', (lambda x: True))
 if kwargs:
  print 'Unknown parameters:', kwargs.keys()
 if (exact_bits is None):
  raise ValueError('Missing exact_bits parameter')
 if (exact_bits < 160):
  raise ValueError('Prime number is not big enough.')
 if (randfunc is None):
  randfunc = Random.new().read
 result = COMPOSITE
 while (result == COMPOSITE):
  candidate = (Integer.random(exact_bits=exact_bits, randfunc=randfunc) | 1)
  if (not prime_filter(candidate)):
   continue
  result = test_probable_prime(candidate, randfunc)
 return candidate

def generate_probable_prime ( ** kwargs ) : exact_bits = kwargs . pop ( 'exact_bits' , None ) randfunc = kwargs . pop ( 'randfunc' , None ) prime_filter = kwargs . pop ( 'prime_filter' , ( lambda x : True ) ) if kwargs : print 'Unknown parameters:' , kwargs . keys ( ) if ( exact_bits is None ) : raise ValueError ( 'Missing exact_bits parameter' ) if ( exact_bits < 160 ) : raise ValueError ( 'Prime number is not big enough.' ) if ( randfunc is None ) : randfunc = Random . new ( ) . read result = COMPOSITE while ( result == COMPOSITE ) : candidate = ( Integer . random ( exact_bits = exact_bits , randfunc = randfunc ) | 1 ) if ( not prime_filter ( candidate ) ) : continue result = test_probable_prime ( candidate , randfunc ) return candidate
generate a random probable prime .