Open In App

Python | sympy.randprime() method

Last Updated : 27 Aug, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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:




# import randprime() method from sympy
from sympy import randprime
  
a = 4
b = 50
  
# Use randprime() method 
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:




# import randprime() method from sympy
from sympy import randprime
  
a = 60
b = 100
  
# Use randprime() method 
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

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads