A detailed analysis of the code generated by python random Numbers

  • 2020-04-02 09:26:03
  • OfStack

The following article mainly introduces the python random number generation code to introduce the python random number generation in the actual operation process of the specific application, if you are interested in its related content, you can click on the following article. I hope you find it rewarding.
The random module in Python is used to generate random Numbers. Here are some of the most commonly used functions in the random module.
 
random.randomrandom.random() 

To generate a random number of characters from 0 to 1:
 
0 <= n < 1.0random.uniformrandom.uniform 

The function prototype is:
 
random.uniform(a, b) 

Used to generate a random number of points in a specified range, with two arguments, one for the upper bound and one for the lower bound. If a > B, then the generated random number n: a < = n < = b. If a < B,
 
b <= n <= a print random.uniform(10, 20) print random.uniform(20, 10) 

Results (different results on different machines)

18.7356606526 # 12.5798298022 random. Randintrandom. Randint ()
The function prototype is:
 
random.randint(a, b) 

Used to generate an integer in a specified range. Where parameter a is the lower limit, parameter b is the upper limit, and python random number generation
 
n: a <= n <= bprint random.randint(12, 20) 

Generated random Numbers

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. The above is an introduction to the actual operation of python random number generation.

Related articles: