Python | sympy.randprime() method
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)
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.
A random prime between 4 and 50 is 37
A random prime between 60 and 100 is 79
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course