Skip to content

Instantly share code, notes, and snippets.

@alice1017
Created December 22, 2010 15:34
Show Gist options
  • Save alice1017/751654 to your computer and use it in GitHub Desktop.
Save alice1017/751654 to your computer and use it in GitHub Desktop.
ランダムな文字列を生成する関数です
#!/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
#!/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