def test_probable_prime(candidate, randfunc=None):
 if (randfunc is None):
  randfunc = Random.new().read
 if (not isinstance(candidate, Integer)):
  candidate = Integer(candidate)
 try:
  map(candidate.fail_if_divisible_by, _sieve_base)
 except ValueError:
  return False
 mr_ranges = ((220, 30), (280, 20), (390, 15), (512, 10), (620, 7), (740, 6), (890, 5), (1200, 4), (1700, 3), (3700, 2))
 bit_size = candidate.size_in_bits()
 try:
  mr_iterations = list(filter((lambda x: (bit_size < x[0])), mr_ranges))[0][1]
 except IndexError:
  mr_iterations = 1
 if (miller_rabin_test(candidate, mr_iterations, randfunc=randfunc) == COMPOSITE):
  return COMPOSITE
 if (lucas_test(candidate) == COMPOSITE):
  return COMPOSITE
 return PROBABLY_PRIME

def test_probable_prime ( candidate , randfunc = None ) : if ( randfunc is None ) : randfunc = Random . new ( ) . read if ( not isinstance ( candidate , Integer ) ) : candidate = Integer ( candidate ) try : map ( candidate . fail_if_divisible_by , _sieve_base ) except ValueError : return False mr_ranges = ( ( 220 , 30 ) , ( 280 , 20 ) , ( 390 , 15 ) , ( 512 , 10 ) , ( 620 , 7 ) , ( 740 , 6 ) , ( 890 , 5 ) , ( 1200 , 4 ) , ( 1700 , 3 ) , ( 3700 , 2 ) ) bit_size = candidate . size_in_bits ( ) try : mr_iterations = list ( filter ( ( lambda x : ( bit_size < x [ 0 ] ) ) , mr_ranges ) ) [ 0 ] [ 1 ] except IndexError : mr_iterations = 1 if ( miller_rabin_test ( candidate , mr_iterations , randfunc = randfunc ) == COMPOSITE ) : return COMPOSITE if ( lucas_test ( candidate ) == COMPOSITE ) : return COMPOSITE return PROBABLY_PRIME
test if a number is prime .