Source code for bag.text.hash

import string  # noqa
from random import choice
from hashlib import sha256


[docs]def random_hash(length: int = 12) -> str: """Generate a random generic hash key.""" assert length > 0 alist = [] for i in range(length): alist.append(choice(string.ascii_letters)) ahash = sha256(''.join(alist).encode('ascii')) return ahash.hexdigest()[:length]