Last active
August 29, 2015 14:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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