Python the random module in is used to generate a stochastic number. Here are some of the most commonly used functions in the random module.
1.random.random
Random.random () is used to generate a random number of 0 to 1 Points: 0 <= N < 1.0
2.random.uniform
The function prototype for random.uniform is: Random.uniform (a, b), which is used to generate a random number of points within a specified range of two parameters, one of which is the upper limit and the other is the lower limit. If a > b, the generated random number n:a <= N <= B. If a <b, then B <= N <= A.
3.random.randint
The function prototype for Random.randint () is: random.randint (a, b), which is used to generate integers in a specified range. Where parameter A is the lower limit, parameter B is the upper limit, the generated random number n:a <= n <= B
4.random.randrange
The function prototype for Random.randrange is: random.randrange ([start], stop[, step]), which gets a random number from the specified range, in the collection incremented by the specified Cardinality. Such as: random.randrange (10, 100, 2), The result is equivalent from [10, 12, 14, 16, ... 96, 98] gets a random number in the Sequence. Random.randrange (10, 100, 2) is equivalent to Random.choice (range (10, 100, 2) on the Result.
5.random.choice
Random.choice gets a random element from the Sequence. Its function prototype Is: Random.choice (sequence). The parameter sequence represents an ordered Type. Here's a note : Sequence is not a specific type in python, but a series of types. list, tuple, string all belong to Sequence. For sequence, You can view the Python manual data Model Chapter.
6.random.shuffle
The function prototype for random.shuffle is: Random.shuffle (x[, random]), which disrupts the elements in a list
7.random.sample
The function prototype for random.sample is: random.sample (sequence, k), which randomly fetches fragments of the specified length from the specified sequence. The sample function does not modify the original sequence.
The above methods are the most common in the random module, and other methods are described in the Python manual. Interested friends can find more detailed information by querying the Python manual.
This article is from the "operations diary" blog, make sure to keep this source http://guyuyuan.blog.51cto.com/8666992/1926178
Python module-random