Created
February 24, 2012 05:51
-
-
Save marazmiki/1898148 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
import datetime | |
import random | |
import string | |
def seq_gen(length=5, uppercase=True, lowercase=True, digits=True, | |
special=True, extra=None): | |
""" | |
Returns the sequence of given length consists of specified | |
group of chars: digits, uppercase, lowercase, punctuation or | |
custom set. | |
""" | |
randomizers = [] | |
c, s = random.choice, string | |
if uppercase: | |
randomizers.append(lambda: c(s.uppercase)) | |
if lowercase: | |
randomizers.append(lambda: c(s.lowercase)) | |
if digits: | |
randomizers.append(lambda: c(s.digits)) | |
if special: | |
randomizers.append(lambda: c(s.punctuation)) | |
if extra: | |
randomizers.append(lambda: c(extra)) | |
if not randomizers: | |
raise TypeError, "Specify at least one char range" | |
return u''.join([c(randomizers)() for _ in xrange(length)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment