The random module is the module used to generate the stochastic number.
- Importing the Random module
Import Random
- Generates a random number of 0~1, floating-point numbers
# Randomly generate a random number of 0~1 Print (Random.random ())
- Generate any range of floating-point numbers
# randomly take a range of floating-point numbers from the list Print (Random.uniform (1,3))
- Generate an integer within [x, Y] Range
# randomly generate a random number Print (Random.randint (1,3))
- Generates an integer in the [x, y) range, with the head not rounded
# Randomly generate a random number of one or more Print (Random.randrange (1,3))
- Randomly select a sequence with multiple elements, such as a list, a tuple, and so on
# randomly take an element from a list Print (Random.choice ([1,2,3,4]))
- Randomly select multiple items in a sequence with multiple elements, such as lists, tuples, and so on
# randomly take 2 elements from a list Print (Random.sample ([1,2,3,4],2)) # printing results for [4, 1]
"Python standard library Module II" Random module learning