Am I programming in Python mode?
Anders M Eriksson
anders.eriksson at morateknikutveckling.se
Wed Feb 2 08:31:32 EST 2000
Hello!
Being new to Python I would like your comments on this function. Is it
written in Pytnon mode?
The function returns a random string, and have 3 params the lenght of
the string, lowercase/Uppercase and dublicates
Any comments and/or suggestions are welcome!!
// Anders
def randStr(n, lower=1, dublicates=1):
# returns a random string with <n> characters
# lower if true only lowercase letters
# dublicates if true then the same letter can be repeated
if lower:
l = ord('a')
h = ord('z')
else:
l = ord('A')
h = ord('z')
str = ""
generator = whrandom.whrandom()
for i in range (n):
ch = generator.randint(l,h)
if dublicates:
str = str + chr(ch)
else:
bRepeat = 1
while bRepeat:
if not chr(ch) in str:
str = str + chr(ch)
bRepeat = 0
else:
ch = generator.randint(l,h)
return str
More information about the Python-list
mailing list