码迷,mamicode.com
首页 > 编程语言 > 详细

Python3_module_random

时间:2019-02-09 15:18:30      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:2.4   def   pytho   ice   author   shuffle   style   shuf   dom   

__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

标签:2.4   def   pytho   ice   author   shuffle   style   shuf   dom   

原文地址:https://www.cnblogs.com/qianjunye/p/10357398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!