Created
December 22, 2010 15:34
-
-
Save alice1017/751654 to your computer and use it in GitHub Desktop.
ランダムな文字列を生成する関数です
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#coding:utf-8 | |
import random | |
def makestr(num): | |
s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789[]{}!$%&'()-^¥:;*+><" | |
strist = list(s) | |
string = "" | |
for i in range(num): | |
x = random.randint(0,len(strlist)-1) | |
string += strlist[x] | |
print string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#coding:utf-8 | |
#文字列をリストにしない場合 | |
import random | |
def makestr(num): | |
s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789[]{}!$%&'()-^¥:;*+><" | |
string = "" | |
for i in range(num): | |
x = random.randint(0,len(s)-1) | |
string += s[x] | |
print string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment