The random module is a module commonly used in Python to generate random numbers or random strings. For example, you want to test a login interface, you need to batch a number of user names, the user name includes uppercase, lowercase letters and numbers, each username can not be repeated, this thing can be given to Python random to achieve.
Let's talk about the basic use of random:
Importrandom,stringPrint(Random.random ())#used to generate random floating-point numbers between 0-1Print(Random.uniform (1,3))#used to generate a random floating-point number between 1-3 (within a specified range)Print(Random.randint (0,20))#used to generate a random integer between 0-20Print(Random.randrange (1,10))#used to generate a range that can be added as a step value, as followsPrint(Random.randrange (2,10,2))#random numbers between 2-10, each number is a value of 2+n*2, that is, only 2, 4, 6, 8, 10, and the result is equivalent to Random.choice (Rango ())Print(Random.choice (range (1,10,2)))#random numbers between 1-10, each number is a value of 1+n*2, that is, only 1, 3, 5, 7, 9, and the result is equivalent to Random.randrange (*,*,*)Print(Random.choice (String.ascii_lowercase))#randomly select a A-Z between a letterPrint(Random.choice (String.ascii_uppercase))#randomly select a A-Z between a letterPrint(Random.choice (String.ascii_letters))#randomly select letters between A-Z and a-Z
Python random module