Copy Code code as follows:
Import Random
Print Random.random ()
Gets a floating-point number less than 1
Copy Code code as follows:
Import Random
Random.randint (1,10)
Gets an integer from 1 to 10
Copy Code code as follows:
Import Random
Print Random.uniform (0,2)
Gets a floating-point number that is greater than 0 or less than 2
Copy Code code as follows:
Import Random
Print Random.randrange (1,10,4)
Gets a random number from 1 to 10 steps to 4
Copy Code code as follows:
Import Random
a=[1,2,3,4,5]
Random.choice (a)
Remove an element from List a randomly
Copy Code code as follows:
Import Random
a=[1,2,3,4,5]
Random.shuffle (a)
Disrupt the order of elements in List A
Copy Code code as follows:
Import Random
a=[1,2,3,4,5]
Random.sample (a,3)
Remove 3 elements from List A in random order (one element can only be fetched once, so the number of fetched cannot be greater than the number of elements contained in the list)