#!/bin/bash # # cprint () { typ=$1 case $typ in v) alpha="aeiouy" ;; c) alpha="bcdfghjklmnpqrstvwxz" ;; V) alpha="AEIOUY" ;; C) alpha="BCDFGHJKLMNPQRSTVWXZ" ;; n) alpha="0123456789" ;; *) echo "** Undefined **" ; exit 1 ;; esac len=${#alpha} r=$((RANDOM%len)) echo -en ${alpha:r:1} } rprint () { code=$1 for i in $(seq 1 ${#code}) do c=${code:i-1:1} cprint $c done echo } rprint "cvccvc" rprint "cvcvvc" rprint "Cvccvc" rprint "Vccvcvc" rprint "Cvnvn"
This decision is easy to change to print a different sequence, easily redefined if you do not agree with y, need Àâü or UPPERCASE, etc.
The experimental result:
gohhec voteup Wuwjut Utpycoq Va6a6
man bash talks about RANDOM:
Every time this parameter is referenced, a random integer from 0 to 32767 ...
So, if you take modulo RANDOM % X , and X is not a power of 2, the lower balances will have better chances than higher once. This should not be important in your case, if you do not go to the extrem with your groups of characters or do not use it in high security zones. :)
source share