I would like to shuffle output of find
BUT with a fixed seed, so that every time I run the command I get the same output.
Here's how I shuffle:
find . -name '*.wav' | shuf
The issue is that every time we have a new seed -> new order. My attempt to fix it:
find . -name '*.wav' | shuf --random-source=<(echo 42)
That works only on occasions (i.e. just a few cases, in a deterministic way). Most of the time it fails with:
shuf: ‘/proc/self/fd/12’: end of file
Same error is produced by e.g.
seq 1 100 | sort -R --random-source=<(echo 42)
That I have seen being used in other places.
This works though:
printf '%s\n' a b c | shuf --random-source=<(echo 42)
Why is that? And how I can fix it? I am open to any suggestions. Output of the find
is a part of a larger script. The solution should work for bash
and zsh
.
Why my solution did not work (EDIT)
Thanks to @franzisk and @Inian I think I understand now why my initial solution did not work. I was looking at --random-source
as it were a seek, while it is, well, "random source" = source of randomness. My echo 42
simply does not provide enough entropy for anything longer than a few lines. That's why it worked only in a couple of cases!
"Seeding" (as in: sending) large number of bytes does the job as it provides enough entropy.