3 ms·
Here is what I happen to have sitting around. (I'm not recommending it; there are much more secure ones. But it's short, and uses a crypto-random generator.)
by abecedarius 12y ago
Here is what I happen to have sitting around. (I'm not recommending it; there are much more secure ones. But it's short, and uses a crypto-random generator.)
import math
from random import SystemRandom
cryptogen = SystemRandom()
alphabet = open('/path/to/a/custom/wordlist').read().splitlines()
assert len(set(alphabet)) == len(alphabet)
def gen_token(length):
return ','.join(cryptogen.sample(alphabet, length))
nbits = 80
length = int(math.ceil(nbits * math.log(2, len(alphabet))))
print gen_token(length)