[HN Gopher] Random Word Generator in Bash
       ___________________________________________________________________
        
       Random Word Generator in Bash
        
       Author : todsacerdoti
       Score  : 14 points
       Date   : 2022-03-19 17:01 UTC (6 hours ago)
        
 (HTM) web link (danielbmarkham.com)
 (TXT) w3m dump (danielbmarkham.com)
        
       | lucb1e wrote:
       | The code renders correctly neither on Firefox (desktop) nor
       | mobile (some webview browser). It goes out of the screen both
       | left and right.
       | 
       | Here it is since paragraph selection (triple click) doesn't exist
       | in tap form on mobile. Added a few newlines because why not.
       | pickaword() {             WORDFREQFILE=/home/mywords.txt;
       | WORDLENGTH=$1;             FREQSUM=$(awk -v
       | wordlength="$WORDLENGTH" 'length($1) == wordlength
       | {s+=$2}END{print s}' "$WORDFREQFILE");             CHOICE=$(shuf
       | -i 0-$FREQSUM -n 1);             awk -v wordlength="$WORDLENGTH"
       | 'length($1) == wordlength {sum += $2; print $1, $2, sum} END
       | {print sum}' "$WORDFREQFILE" | awk -v threshold="$CHOICE" '$3 <
       | threshold' | tail -2 | head -1 | cut -f1 -d' ';         }
       | 
       | If you just want to generate random words (I use this from time
       | to time) (note: do not use for cryptographic purposes!), you can
       | just do `shuf /usr/share/dict/words | head -1` on most linux
       | systems (since most have a dictionary installed; else you might
       | have to apt install wamerican or something), but of course that
       | doesn't take language frequency into account like OP has. To
       | select a word length you could do `grep ^....$
       | /usr/share/dict/words | shuf | head -1` with the number of dots
       | being the number of characters.
        
         | DanielBMarkham wrote:
         | Fixed. Checked on FF on Pixel and Chrome on generic droid.
         | Thanks.
        
       ___________________________________________________________________
       (page generated 2022-03-19 23:01 UTC)