1. 程式人生 > >python3.7 random模塊

python3.7 random模塊

class print res return pytho 必須 pan string .sh

#!/usr/bin/env python 
__author__ = "lrtao2010" 

#python3.7 random模塊

import random
#隨機模塊
# res0 = random.random() #從0~1中間隨機產生一個小數點後16位的浮點數
# res1 = random.uniform(1,3) #從1~3中間隨機產生一個小數點後16位的浮點數
# res2 = random.randint(1,3) #[1,3]
# res3 = random.randrange(1,3) #[1,3)
#
# print(res0)
# print(res1)
# print(res2)
# print(res3) # 0.2606221247506799 # 2.8556674313380523 # 3 # 1 # l0_test = random.choice([11,‘22‘,‘test‘]) #從列表中隨機選擇一個元素 # l1_test = random.choices([11,22,33]) #從列表中隨機選擇一個元素組成一個新列表 # l2_test = random.sample([11,‘22‘,‘test‘,33,44],3) #必須指定選擇的元素個數, # # print(l0_test,type(l0_test)) # print(l1_test,type(l1_test))
# print(l2_test) # 22 <class ‘str‘> # [11] <class ‘list‘> # [44, ‘test‘, ‘22‘] # l_test = [1,2,3,4,5] # random.shuffle(l_test) #將列表元素順序打亂 # print(l_test) # [4, 2, 3, 1, 5] #隨機生成驗證碼 # def v_code(): # res = [] # for i in range(5): # my_number = str(random.randint(0,9)) # my_string = chr(random.randint(64,90))
# my_res = random.choice([my_number,my_string]) # res.append(my_res) # return ‘‘.join(res) # # if __name__ == ‘__main__‘: # print(v_code())

python3.7 random模塊