Skip to content

Instantly share code, notes, and snippets.

@oscarcp
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscarcp/af032f3929e3060aff86 to your computer and use it in GitHub Desktop.
Save oscarcp/af032f3929e3060aff86 to your computer and use it in GitHub Desktop.
Token generator (does not differentiate EOF from duplicate) Takes around 2 seconds for 25k entries
import binascii
import os
import sys
import time
start_time = time.time()
iterations = 25000
current = 0
characters = 3
f = open('numbers.txt', 'w')
while current < iterations:
token = binascii.hexlify(os.urandom(characters)).upper()
line = token + '\n'
f.write(line)
current += 1
print token
f.close()
f = open('numbers.txt', 'r')
print "Check if it is duplicated..."
duplicate = 1
while duplicate:
for i in f.readlines():
if line == i:
print "KILL IT WITH FIRE! (wait, is this EOF??)"
token = binascii.hexlify(os.urandom(6))
line = token + '\n'
else:
sys.stdout.write(".")
#sys.stdout.write('\r' + ' ' * (characters / 2))
duplicate = 0
elapsed_time = time.time() - start_time
print "Generation took: %s" % time.strftime('%H:%M:%S', time.localtime(elapsed_time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment