Created
January 6, 2023 09:30
-
-
Save etienne87/1ddb0de92dde11883cd081af6294fcb5 to your computer and use it in GitHub Desktop.
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 numpy as np | |
import hashlib | |
with open('names.txt', 'r') as f: | |
names = f.read().splitlines() | |
def uid2name(string, num): | |
hashobj = hashlib.sha256(string.encode('utf-8')) | |
val_hex = int(hashobj.hexdigest(), 16)%(2**32-1) | |
np.random.seed(val_hex) | |
idx = np.random.randint(0, len(names), (num,)) | |
name = "-".join([names[i] for i in idx]) | |
return name | |
if __name__ == '__main__': | |
import fire;fire.Fire(uid2name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
script to choose a name from any string