Skip to content

Instantly share code, notes, and snippets.

@Lvl4Sword
Last active May 1, 2016 03:45
Show Gist options
  • Save Lvl4Sword/6edc0dd605a4f457b05d to your computer and use it in GitHub Desktop.
Save Lvl4Sword/6edc0dd605a4f457b05d to your computer and use it in GitHub Desktop.
Simple Psuedo-Random Number Generation
# Using SystemRandom which is cryptographically secure[1],
# this prints out 64 psuedorandom characters for you to use in whatever.
# [1]https://docs.python.org/2/library/random.html
# "( Use os.urandom() or SystemRandom if you require a
# cryptographically secure pseudo-random number generator. )"
import random
import string
import sys
version_check = sys.version_info[0]
if version_check == 2:
letters = string.letters
print_this = ''.join(ransys.choice(characters) for x in xrange(64))
else:
letters = string.ascii_letters
print_this = ''.join(ransys.choice(characters) for x in range(64))
ransys = random.SystemRandom()
characters = string.digits + letters + string.punctuation
print(print_this)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment