by aaossa on 11/28/22, 8:28 PM with 1 comments
by Someone on 11/28/22, 9:31 PM
That’s why shuf isn’t a “program that does one thing and does it well”, and allows for a few simple optimization steps:
- use the “-i” option to get rid of the seq process:
shuf -i1-6 | head
- use the “-n” option to get rid of the head process: shuf -i1-6 -n 1
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.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.