Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def easy_string(length=10, repeatable=True, chars='23469cdfghjkmnpqrtvwxy'):
- '''Returns a string with specific characters.
- Mainly used to make sure the string doesn't contain characters that can
- be easily confused such as the number 0 and letter o
- NOTE do I need to make this unicode safe?
- '''
- choice = random.choice
- output = None
- if repeatable:
- output = (choice(chars) for i in range(length))
- else:
- output = []
- last_char = None
- current_char = None
- for i in range(length):
- added = False
- while not added:
- current_char = choice(chars)
- if current_char is None or current_char != last_char:
- output.append(current_char)
- last_char = current_char
- added = True
- return ''.join(output).upper()
Add Comment
Please, Sign In to add comment