daily pastebin goal
88%
SHARE
TWEET

randomCharacters.py

a guest Jan 24th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # randomCharacters.py
  2. # Program that generates random PLAINTEXT combinations of characters
  3.  
  4. import random
  5. import string
  6. import os
  7.  
  8. def main():
  9.     print("\nCreates random combinations of characters based on user input.\n")
  10.  
  11.  
  12.     # Get user input (amounts, symbols yes/no, min length, max length)
  13.     combination_amount = int(input("How many combinations should be generated? "))
  14.     c_symbol = str(input("Can punctuation and special characters be used (Y/N)? "))
  15.     if c_symbol == "y" or c_symbol == "Y":
  16.         c_symbol = string.punctuation
  17.     else:
  18.         c_symbol = ""        
  19.     c_min_char = int(input("Minimum number of characters? "))
  20.     c_max_char = int(input("Maximum number of characters? "))
  21.     if c_max_char < c_min_char:
  22.         c_min_char, c_max_char = c_max_char, c_min_char
  23.  
  24.  
  25.     # Create a file for the PLAINTEXT combinations and write to it
  26.     filename = "random_combinations"  
  27.     while os.path.isfile(filename + ".txt") == True: # Adds _new to the name if file exists
  28.         filename += "_new"
  29.     filename += ".txt"
  30.     f = open(filename, "w")
  31.  
  32.  
  33.     # Generate combinations using the random and string modules, and writes it as PLAINTEXT to the file
  34.     for i in range (combination_amount):
  35.         combination_mixer = "".join(random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits + c_symbol, k=random.randint(c_min_char, c_max_char)))
  36.         f.write(combination_mixer + "\n")
  37.  
  38.  
  39.     # Save the file and open it for the user
  40.     print("Generated", combination_amount, "combinations.\nSaved as:", os.getcwd() + "\\" + filename)
  41.     f.close()
  42.     os.startfile(os.getcwd() + "\\" + filename)
  43.  
  44.    
  45.     run_again = str(input("Run again (Y/N)? "))
  46.     if run_again == "Y" or run_again == "y":
  47.         main()
  48.        
  49.  
  50. if __name__ == "__main__":
  51.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top