Import: import random
Random Decimal: random.random (): decimal between greater than 0 and less than 1
Decimal between specified number does not include the specified maximum: random.uniform ()
Random integer: random.randint (1,5): greater than or equal to 1 and less than equal to an integer between 5
Designated odd or even, using steps: random.randrange (1,19, step)
And randomly select a return, there will be a repeating element, returns a list form: random.choice ((1,2,3,), k = 3), 3 elements appear
Arbitrarily selected three elements appear, will not be repeated: random.sample ([1 "23" 3432] k = 3)
random.shuffle (): scramble input, in situ (primary memory) disrupted
练习:随机生成验证码 import random def 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="".join([code,str(add)]) return code print(v_code())
Python random module from the entry to the autistic
Guess you like
Origin www.cnblogs.com/heyulong1214/p/11528133.html
Recommended
Ranking