1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-11-15 05:45:55 +05:30
gists/python-programming/generate_C_lang_token.py

28 lines
759 B
Python
Raw Normal View History

2024-02-24 23:40:48 +05:30
#!/usr/bin/python3
# generate_C_lang_token.py
#
# Author: Intel A80486DX2-66
# License: Creative Commons Zero 1.0 Universal
#
# TODO: If the generated token starts with `__`, replace the first 2 characters
# to a random [A-Za-z]{2,2} string
2024-02-24 23:40:48 +05:30
from random import choice
from string import ascii_lowercase, ascii_uppercase, digits
from sys import argv, stdin
2024-02-24 23:40:48 +05:30
first_char_alphabet = ascii_uppercase + ascii_lowercase + "_"
alphabet = first_char_alphabet + digits
random_token = lambda n: \
"".join( \
[choice(first_char_alphabet)] + \
[choice(alphabet) for i in range(n - 1)]) if (n := int(n)) > 0 else ""
if "-" in argv[1:] and stdin:
print(random_token(list(stdin)[0]))
else:
print("Random token:", random_token(input("Token length? ")))
2024-02-24 23:40:48 +05:30