The overhead of the Unix philosophy for such simple steps is gigantic. The example (<i>seq 1 6 | shuf | head -n 1</i>) creates three processes, pipes six strings between the first and the second, and one of them on to the third, and likely calls a RNG six times.<p>That’s why <i>shuf</i> isn’t a “program that does one thing and does it well”, and allows for a few simple optimization steps:<p>- use the “-i” option to get rid of the <i>seq</i> process:<p><pre><code> shuf -i1-6 | head
</code></pre>
- use the “-n” option to get rid of the <i>head</i> process:<p><pre><code> shuf -i1-6 -n 1
</code></pre>
One process, no pipes, but it probably (I didn’t check the source code) still creates those six strings, and makes those 6 RNG calls.<p>Even that wastes time and memory. If you’re simulating a large die (say a 10,000-sided one) you may be better of running an awk or Perl script that calls a RNG once.