Guest User

Untitled

a guest
Oct 20th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. def easy_string(length=10, repeatable=True, chars='23469cdfghjkmnpqrtvwxy'):
  2.     '''Returns a string with specific characters.
  3.    
  4.    Mainly used to make sure the string doesn't contain characters that can
  5.    be easily confused such as the number 0 and letter o
  6.  
  7.    NOTE do I need to make this unicode safe?
  8.    '''
  9.     choice = random.choice
  10.     output = None
  11.     if repeatable:
  12.         output = (choice(chars) for i in range(length))
  13.     else:
  14.         output = []
  15.         last_char = None
  16.         current_char = None
  17.         for i in range(length):
  18.             added = False
  19.             while not added:
  20.                 current_char = choice(chars)
  21.                 if current_char is None or current_char != last_char:
  22.                     output.append(current_char)
  23.                     last_char = current_char
  24.                     added = True
  25.     return ''.join(output).upper()
Add Comment
Please, Sign In to add comment