random 模块 python 生成大写字母,小写字母及数字的5位随机数
import random print(random.random()) #0.1-1 print(random.randint(1,8)) #1-8 print(random.choice("helloworld")) #h e l l o w o r l d 打散字符串,随机输出一个。 print(random.choice(["123","456","777"])) #[]这种形式???777 print(random.choices(["123","456","777"])) #[]这种形式??? str 字符串[‘777‘] # print(help(random.shuffle)) # print(random.shuffle())######干啥的不知道? print(random.sample("helloworld",2)) #这个可以定义选出2个,并返回[‘e‘, ‘l‘] print(random.sample(["123","456","777"],2))#同上,,,[‘456‘, ‘777‘] 可随机输出2个 print(random.randrange(1,200))#输出不包含200,最后一个不包含的情况用的比较多哦。
玩个随机数
import random def v_code(): code = "" for i in range(5): add_num = str(random.randrange(0,9)) add_al = chr(random.randrange(65,91))#chr转换为A-Z大写。print(chr(90))#65-90任意生成A-Z sj = random.choice([add_num,add_al,add_al.lower(),add_num])#str.lower()转换为小写,为了保证概率,将_add_num写两遍,这样,字母和数字概率一样了 code = "".join([sj,code]) return code print(v_code())
相关推荐
jessieHJ 2020-05-31
Lexan 2020-04-15
georgeandgeorge 2019-12-28
wordmhg 2019-10-26
chunjiekid 2019-03-21
zhlyks 2019-05-31
huakai 2018-02-23
katnisswuyuechen 2018-05-26
helen0 2017-04-18
prettyice 2010-03-24
wyqwilliam 2019-10-26
ganyouxianjava 2010-03-23
shlamp 2019-06-30
Kwong 2019-06-29
xiaouncle 2020-07-31
guangyacyb 2020-06-14
pengkunstone 2020-06-09