Import Random # Number Import string
Random decimals
Print (Random.random ())0.8681861054821751
Random Print in 1-5 range
Print (Random.randint (1,5))1
and Randint difference in 1-4 range random print
Print (Random.randrange (1,5))3
Randomly take 5 numbers out of this range and print them in list mode.
Print (Random.sample (5))[+, 94, +] Print (Random.sample ('abcdef', 5)) ['b' D ' ' F ' ' e ' ' C ']
Print 0-9 numbers
Print (string.digits) 0123456789
Print A-Z
Print (string.ascii_letters) abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
Randomly take out 0-9 A-Z inside random numbers printed in string format
Str_source = string.ascii_letters + string.digitsprint(". Join (Random.sample (Str_source , 5))) dzn5w
Choice Random Pass sequence primitive, string, list inside random number
Print (Random.choice ([1,3,5]))5Print(Random.choice ('helo')) e
Shuffle function
L = [1,2,3,4,5,6,7,8]print(l) [1, 2, 3, 4, 5, 6, 7, 8]random.shuffle (l) Print(l) [6, 2, 5, 3, 4, 8, 1, 7]
random number verification Code applet
Import" for" in range (5): = Random.randrange (0,5) if current! = i := Chr (Random.randint (65,90) )elif I > 2: = Chr (Random.randint (97,122)) Else: = Random.randint (0,9) + = Str (temp)print(checkcode)
Python random module