Day6 random Number Module, day6random random Number Module
Random
We often see Random verification codes of websites, which are generated by random numbers. Therefore, we need to know the random number module. How to generate a random number.
Random Number generated by random
Random. random () generates decimal places between 0 and 1.
>>> Import random
>>> Random. random ()
0.7386445925394346
Random. randint (1, 3) generates an integer random number between 1 and 3
>>> Random. randint (1, 5)
4
>>> Random. randint (1, 5)
5
Randrange (self, start, stop = None, step = 1, _ int = int)Def randrange (self, start, stop = None, step = 1, _ int = int ):
"Choose a random item from range (start, stop [, step]).
This fixes the problem with randint () which provided des
Endpoint; in Python this is usually not what you want.
"""
# This code is a bit messy to make it fast for
# Common case while still doing adequate error checking.
Randrange (self, start, stop, sep) generates a random number. You can define the step size.
>>> Random. randrange (1, 9, 2)
3
>>> Random. randrange (1, 8, 2)
1
>>> Random. randrange (1, 8, 2)
3
Generate a random number of 5 digits, for example:
>>> Random_num = random. randint (random, 99999)
>>> Random_num
90821
Method 2:
Import random
Nums = []
For I in range (5 ):
If I = random. randint (1, 5 ):
Nums. append (str (I ))
Else:
Nums. append (chr (random. randint (65,90 )))
Else:
Print ("". join (nums ))
The running result is as follows:
CU23M