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)

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

My Personal Notes arrow_drop_up Coder Machine Learner Social Activist Vocalist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.