python module -- random module

1  import random
 2  
3  print (random.random())   #Randomly generate a (0,1) float 0.026244299361600776 
4  
5  print (random.randint(1,4))   # [1,4] -----> random integer 3 
6  
7  print (random.randrange(1,3)) # [1,3) -----> random integer 2 
8  
9  print (random.choice([1, ' a ' , ' 43 ' , [5,6]])) #Inside is an iterable object, from which a 43 
10  
11 is randomly generated  print (random.sample([1, ' a' , ' 43 ' ,[5,6]],2)) #Inside is a list [ ' 43 ', [5, 6 ]]
 12  
13  print (random.sample((1, ' a ' , ' 43 ' ,[5,6]),2)) #It is an iterable object, and two are randomly selected from the same inside [ ' 43 ', 1 ]
 14  
15  print (random.uniform(1,3)) #From [ 1,3] Randomly generate a float 2.1721533676198015 
16  
17 res = [ 1,3,4,5,6 ]
 18 random.shuffle(res) #Shuffle   the order by 
19 print(res)                               [1, 4, 6, 3, 5]
1 0.026244299361600776
2 3
3 2
4 43
5 ['43', [5, 6]]
6 ['43', 1]
7 2.1721533676198015
8 [1, 4, 6, 3, 5]

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325274333&siteId=291194637