Skip to content

Instantly share code, notes, and snippets.

@xbalaji
Last active October 8, 2020 06:26
Show Gist options
  • Save xbalaji/8447f043367c3361a1f89c4789edc14e to your computer and use it in GitHub Desktop.
Save xbalaji/8447f043367c3361a1f89c4789edc14e to your computer and use it in GitHub Desktop.
python_random_strings.sh
# generate string list
python3 -c 'import random,json,string; print([ "".join([random.choice(string.ascii_letters) for ix in range(15)]) for jx in range(10)])'
# print one each line, logic is to create a list first and use print with * and separator
python3 -c 'import random,string; sx = ["".join([random.choice(string.ascii_letters) for ix in range(15)]) for jx in range(10)]; print(*sx, sep="\n")'
# generate a csv file, the one below generates a csv file with random people name and age, change the tuple to more than 2, you could create address
python3 -c 'import random,string; ppl = [("".join(random.choice(string.ascii_letters) for ix in range(6)), random.randrange(20,90)) for jx in range(10)]; [print(f"{name}, {age}") for name, age in ppl]'
# generate AWS account numbers, random 12 digit number, primarily used for testing
python3 -c 'import random; acc = ["".join([str(random.randrange(10)) for ix in range(12)]) for jx in range(10)]; print(*acc, sep="\n")'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment