I have an array in Bash, say it contains the numbers {1, 2, 3, 4, 5}. I want to extract some of those numbers randomly, such that the same number doesn’t get extracted twice.
Basically, if I wanted to extract 3 numbers from the array, I want results like: {3, 4, 1} or {5, 2, 4} and not {1, 1, 3} or {2, 5, 2}.
I’ve tried deleting elements as I extract them, but it always seems to mess up. Can anyone help?
Decided to write an answer, as I found the
--input-rangeoption toshufthat turned out handy: