Pre-Knowledge points:
The random module in Python is used to generate a stochastic number.
Import Randomdef V_code (): code = "for i in range (5): num=random.randint (0,9) ALF=CHR ( Random.randint (65,90)) add=random.choice ([num,alf]) code + = str (add) return Codeprint (V_code ())
Other functions in the random module:
Import Randomprint random.random () #获取一个小于1的浮点数 import randomrandom.randint (1,10) #获取一个从1到10的整数import Randomprint Random.uniform (0,2) #获取一个大于0小于2的浮点数 import randomprint random.randrange (1,10,4) #获取一个从1到10步长为4的随机数 import randoma=[ 1,2,3,4,5]random.choice (a) #从列表a从随机取出一个元素 import Randoma=[1,2,3,4,5]random.shuffle (a) #打乱列表a里元素的顺序 import randoma=[ 1,2,3,4,5]random.sample (a,3) # Remove 3 elements from List A in random order (one element can only be removed once, so the number of extracts cannot be greater than the number of elements contained in the list)
Python implements random verification code