Python | sympy.randprime() method
Last Updated :
27 Aug, 2019
With the help of sympy.randprime() method, we can find a random prime number in the range [a, b), where a and b are parameters to the method.
Syntax: randprime(a, b)
Parameter:
a – It denotes the start of the range. It is inclusive.
b – It denotes the end of the range. It is not inclusive.
Returns: Returns a random prime in the given range. If no prime is present in the range then it raises a ValueError.
Example #1:
from sympy import randprime
a = 4
b = 50
a_randprime_b = randprime(a, b)
print ( "A random prime between {} and {} is {}" . format (a, b, a_randprime_b))
|
Output:
A random prime between 4 and 50 is 37
Example #2:
from sympy import randprime
a = 60
b = 100
a_randprime_b = randprime(a, b)
print ( "A random prime between {} and {} is {}" . format (a, b, a_randprime_b))
|
Output:
A random prime between 60 and 100 is 79
Share your thoughts in the comments
Please Login to comment...