Created
July 16, 2023 21:45
-
-
Save remram44/b2ff04d4f623792560d84511715c885b 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
#!/usr/bin/env python3 | |
# From http://hewo.xedoloh.com/2015/04/base-256/ | |
# Usage: | |
# name256 | |
# Generate a random base256 word | |
# Example: | |
# $ name256 | |
# vic | |
# name256 <N> | |
# Generate N random base256 words | |
# Example: | |
# $ name256 3 | |
# pic bif jed | |
# name256 - [X [Y [...]]] | |
# Encode the given numbers into base256 words | |
# Example: | |
# $ name256 - 3 62 0x1f | |
# bam jof gom | |
import random | |
import sys | |
def name(number): | |
s = number // 16 | |
v = (number // 4) % 4 | |
e = number % 4 | |
return ( | |
'bghjklnpqrstvwyz'[s] | |
+ 'aeio'[v] | |
+ 'cdfm'[e] | |
) | |
if __name__ == '__main__': | |
if len(sys.argv) > 1: | |
if sys.argv[1] == '-': | |
names = [name(int(arg, 0)) for arg in sys.argv[2:]] | |
print(' '.join(names)) | |
else: | |
assert len(sys.argv) == 2 | |
nb = int(sys.argv[1], 0) | |
names = [name(random.randint(0, 255)) for _ in range(nb)] | |
print(' '.join(names)) | |
else: | |
print(name(random.randint(0, 255))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment