Skip to content

Instantly share code, notes, and snippets.

@sampollard
Last active August 30, 2020 06:36
Show Gist options
  • Save sampollard/a603599015dda34c7e8a3a773d0774b7 to your computer and use it in GitHub Desktop.
Save sampollard/a603599015dda34c7e8a3a773d0774b7 to your computer and use it in GitHub Desktop.
Generate Random Names
#!/bin/bash
# Generates random roman names plus its gender
# Names copied from https://www.behindthename.com/names/usage/ancient-roman
# First preprocessed by
# awk 'FNR%2 {print $1 " " $2}' roman-names.txt > roman-names.csv
# Surnames copied from https://en.wikipedia.org/wiki/List_of_Roman_nomina
CNT=$1
if [ "$#" -ne 1 ]; then
CNT=5
fi
gawk -v CNT=$CNT \
'BEGIN {fn = 0; fs = 0; srand(systime());}
FILENAME=="roman-names.csv" { f[FNR] = $0; fn++;}
FILENAME=="roman-surnames.csv" { s[FNR] = $0; sn++;}
END {
# print ("Generating with " fn " first names and " sn " surnames.");
for (i=0; i<CNT; i++)
printf ("%s %s\n", f[int(rand()*(fn+1))], s[int(rand()*(sn+1))]);
}' roman-names.csv roman-surnames.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment