If you are confused about the actual application of python random number generation, you can understand it through the following content, the following articles introduce the python random number generation code to introduce the specific application of Python random number generation in the actual operation process, if you are interested in related content, you can click the following article. I hope you will get something from it.
The random module in Python is used to generate random numbers. The following describes the most common functions in the random module.
The code is as follows:
Random. randomrandom. random ()
Used to generate a random number of points ranging from 0 to 1:
The code is as follows:
0 <= n <1.0random.uniformrandom.uniform
Function prototype:
The code is as follows:
Random. uniform (a, B)
Generate a random number of characters in a specified range. one of the two parameters is the upper limit and the other is the lower limit. If a> B, the random number n: a <= n <= B. If
The code is as follows:
B <= n <= a print random. uniform (10, 20) print random. uniform (20, 10)
Result (results on different machines are different)
18.7356606526 #12.5798298022 random. randintrandom. randint ()
Function prototype:
The code is as follows:
Random. randint (a, B)
Generates an integer in the specified range. Here, parameter a is the lower limit, parameter B is the upper limit, and python random number generation
The code is as follows:
N: a <= n <= bprint random. randint (12, 20)
Random number generated
N: 12 <= n <= 20 print random. randint (20, 20)
The result is always
The code is as follows:
20 # print random. randint (20, 10)
This statement is incorrect. The lower limit must be less than the upper limit. The above content is an introduction to the actual operations on python random number generation.