四种方法,生成随机码
最近项目需要随机码,查了查找到四种方法,在这里罗列出来,以备不时之需
由于RHEL 8 只支持Python 3.6,所以2.7的就不研究了(PS:毫无歧视2.7的意思,单纯的为了以后安装CentOS 8 做准备)
# vim 666.py import random import string seed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" sa = [] for i in range(123): sa.append(random.choice(seed)) salt1=''.join(sa) print(salt1) salt2 = ''.join(random.sample(string.ascii_letters + string.digits, 60)) print(salt2) salt3 = random.randint(100000,999999) print(salt3) salt4 = "" for i in range(20): #循环20次,从0到19 salt5 = random.randrange(0,6) #这个随机数为2或者4时,生成一个1到9的随机数放到字符串中 if salt5 == 2 or salt5 == 4: salt4 = salt4 + str(random.randrange(0,10)) else: salt6 = chr(random.randrange(65,122)) salt4 = salt4 + salt6 print(salt4) # python3.6 666.py
效果如下:

Today, I went to the beachfront with my children. I found a sea
shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She
put the shell to her ear and screamed. There was
a hermit crab inside and it pinched her ear. She never wants to
go back! LoL I know this is entirely off topic but
I had to tell someone!
Hi there! Would you mind if I share your blog with my myspace group?
There’s a lot of folks that I think would really enjoy your content.
Please let me know. Thank you
Great blog here! Also your site loads up very fast!
What web host are you using? Can I get your affiliate link to your host?
I wish my web site loaded up as fast as yours lol
You actually make it appear so easy along with your presentation however I
to find this matter to be really something which I feel I
might never understand. It sort of feels too complex and extremely huge for me.
I am taking a look ahead for your next submit,
I’ll attempt to get the hold of it!
Hey there are using WordPress for your site platform?
I’m new to the blog world but I’m trying to get started and create my own. Do you need any
coding knowledge to make your own blog? Any help would
be really appreciated!
Hola! I’ve been following your website for a long time now and finally got the courage to go ahead
and give you a shout out from Lubbock Texas! Just wanted
to mention keep up the good work!