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

25 lines
616 B
Python

#!/usr/bin/python3
# generate_C_lang_token.py
#
# Author: Intel A80486DX2-66
# License: Unlicense
from random import choice
from string import ascii_lowercase, ascii_uppercase, digits
from sys import argv, stdin
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? ")))