def randprime(a, b):
 if (a >= b):
  return
 (a, b) = map(int, (a, b))
 n = random.randint((a - 1), b)
 p = nextprime(n)
 if (p >= b):
  p = prevprime(b)
 if (p < a):
  raise ValueError('no primes exist in the specified range')
 return p

def randprime ( a , b ) : if ( a >= b ) : return ( a , b ) = map ( int , ( a , b ) ) n = random . randint ( ( a - 1 ) , b ) p = nextprime ( n ) if ( p >= b ) : p = prevprime ( b ) if ( p < a ) : raise ValueError ( 'no primes exist in the specified range' ) return p
return a random prime number in the range [a .