📜  Python| sympy.randprime() 方法

📅  最后修改于: 2022-05-13 01:54:38.658000             🧑  作者: Mango

Python| sympy.randprime() 方法

借助sympy.randprime()方法,我们可以在[a, b)范围内找到一个随机素数,其中ab是该方法的参数。

示例 #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))

输出:

A random prime between 4 and 50 is 37

示例 #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))          

输出:

A random prime between 60 and 100 is 79