1. 5
  1. 3

    Fun problem. Would you mind if I posted it on codegolf.stackexchange.com with an attribution to you?

    My solution in J, using a function that takes the wordlist as the left argument and the counts as the right argument: {~[:(I.?@{:)+/\

    Try it online!

    1. 2

      pick() { grep -E "^.{$1}$" /your/word/list | shuf -n1; }

      1. 1

        Not shorter, but because OP likes awk(1):

        pick() {
            awk -v wordlength="$1" 'BEGIN {srand()} {if (length($1) == wordlength) words[i++] = $1} END {print words[int(rand() * i)]}' /usr/share/dict/words
        }
        
        1. 1

          I hate to nitpick, but note that the function picks a word based on the frequency of that word in a specific corpus, in this case Wikipedia. It just doesn’t pick a random word.

          Apologies. I was trying to ignore this misunderstanding, but it’s probably important for future readers to understand the difference between what the code in the essay does and what these great examples do.