4 ms·
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 para
by lucb1e 5y ago
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.
- chlorion 5y agoshuf has flag to make it use an alternative source for randomness. If we pass in a secure source of randomness such as /dev/urandom would shuf work for crypto purposes?
- lucb1e 5y agoPotentially, but since it's not advertised as such (at least I don't see it in the man page) I would not rely on it without someone actually checking the source code properly.
- DanielBMarkham 5y agoFixed. Checked on FF on Pixel and Chrome on generic droid. Thanks.