Skip to content

Instantly share code, notes, and snippets.

@etienne87
Created January 6, 2023 09:30
Show Gist options
  • Save etienne87/1ddb0de92dde11883cd081af6294fcb5 to your computer and use it in GitHub Desktop.
Save etienne87/1ddb0de92dde11883cd081af6294fcb5 to your computer and use it in GitHub Desktop.
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)
@etienne87
Copy link
Author

script to choose a name from any string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment