From c4dd1605a595f22fa7eb32c31c73c854a7652bba Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 5 Jan 2021 20:41:22 -0800 Subject: [PATCH] Add passwordy.random_hex in addition to urandom_hex. --- voussoirkit/passwordy.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/voussoirkit/passwordy.py b/voussoirkit/passwordy.py index aab6b22..afc9343 100644 --- a/voussoirkit/passwordy.py +++ b/voussoirkit/passwordy.py @@ -1,3 +1,6 @@ +''' +This module provides functions for generating random strings. +''' import math import os import random @@ -129,12 +132,17 @@ def make_sentence(length=None, joiner=' '): result = joiner.join(words) return result -def urandom_hex(length): +def random_hex(length): randbytes = os.urandom(math.ceil(length / 2)) token = ''.join('{:02x}'.format(x) for x in randbytes) token = token[:length] return token +def urandom_hex(length): + randbytes = os.urandom(math.ceil(length / 2)) + token = ''.join('{:02x}'.format(x) for x in randbytes) + token = token[:length] + return token def main_password(argv): length = listget(argv, 0, DEFAULT_LENGTH)