1. 程式人生 > >Python3_module_random

Python3_module_random

pytho amp ont choice font 驗證 return python bsp

__author__ = "jocket2333"

import random

print(random.random())
# (0, 1)------ float
print(random.randint(1, 3))
# [1, 3]
print(random.randrange(1, 3))
# [1, 3)
print(random.choice([1, ‘23‘,[4, 5]]))
# 23
print(random.sample([1, ‘23‘, [4,5]], 2))
# [[4, 5], ‘23‘]
print(random.uniform(1, 3))
# 2.4493238844781944

# item = [1, 3, 5, 7,9]

# random.shuffle(item)
# 任意排序
# print(item)
# [7, 3, 1, 5, 9]
#--------------------------------------------------------------
項目:驗證碼
__author__ = ‘jocket2333‘

import random

def v_code():

code = ‘‘
for i in range(5):

num = random.randint(0,9)
alf = chr(random.randint(65, 90))
add = random.choice([num, alf])
code += str(add)

return code
print(v_code())
 

Python3_module_random