If you do not understand the relationship between the random number generated in Python and the most commonly used functions in the random module, the following article describes the relationship between the random number generated in Python and the most commonly used functions in the random module, I hope you will have some gains. The following is an introduction to this article.
Random. random () is used to generate
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, a random number is generated.
- N: a <= n <= B. If a <B, B <= n <=.
-
- print random.uniform(10, 20)
- print random.uniform(20, 10)
- #----
- #18.7356606526
- #12.5798298022
- random.randint
Generates an integer in the specified range. Here, parameter a is the lower limit, parameter B is the upper limit, and Python generates random numbers.
- Print random. randint (12, 20) # generated random number n: 12 <= n <= 20
- Print random. randint (20, 20) # The result is always 20
- # Print random. randint (20, 10) # This statement is incorrect.
The lower limit must be less than the upper limit.
- random.randrange
This article describes the application that generates a random number in python from a set that increments by a specified base number within a specified range.