Randomly pick N characters from a given string(or standard input), just like rolling a dice repeatedly, then concatenate them into a single string.
Please note that:
-
It might containe repeated items. If you want to just shuffle them, try removing
-r
option fromshuf
command. -
It will treat unicode character as one item. see below:
grep -o . <<< "I ♥ Gawr gura" | shuf -rn 20 | paste -sd '' # r♥wa raG r ga w ♥♥ # Guagwwu g ♥ uar♥ # ugIg ♥GrG ur rIwu # ...
use
fold
instead if you are aware of what exactly you are trying to do.fold -w 1 <<< "I ♥ Gawr gura" | shuf -rn 20 | paste -sd '' # IwIg gGg �rI ��wG # G�Iw� GGa rr aIr �G # G G� a u � Gur�ugw w # ...
-
It will pick 10 characters by default if you haven't specified anything yet.
./roll.sh <<< ABC # BAAACBBACA
./roll.sh 3 <<< ABC # CCA