random nonce module (library)
1, random.randint (a, b) : generating a random integer within a certain range
[a, b], can take the a, can be taken to B
2, random.random (): random between 0-1 floating point number
[0, 1), can take to 0, 1 fail to
3, random.uniform (a, b) : a random real number within a range
[a, B], can take the a, can take to B
. 4, random.randrange (start, STOP, STEP): generating a random integer within a range
[start, stop), can take to start, fail to STOP
. 5, the random.choice (sequence): returns the random sequence in a number of
6, random.shuffle (): break, disrupting, chaordic
Note: this function does not return a value, the result of the direct effect on the original scrambled list
7, random.sample (population, k ): sampling
Population: sampling an object
k: the number of samples
1 import random 2 3 r1 = random.random() 4 print(r1) # 0.2682469766947404 5 6 r2 = random.randint(1, 10) 7 print(r2) # 10 8 9 r3 = random.uniform(1, 10) 10 print(r3) # 5.296020606206669 11 12 r4 = random.randrange(0, 11, 2) 13 print(r4) # 10 14 15 r5 = random.choice(["rose", " Cucumber " , " noodles " ]) 16 Print (R5) # cucumber . 17 18 is List1 = [. 1, 2,. 3,. 4,. 5 ] . 19 R6 = random.shuffle (List1) # None 20 is Print (List1) # [. 4,. 1, 2,. 3,. 5] 21 is 22 is R7 = random.sample (List1,. 3 ) 23 is Print (R7) # [. 3, 2,. 5]