I know I can use seq
to generate a random list of numbers: 1, 2, 3, 4…
I want to get those numbers into a random order like 3, 1, 4, 2…
I know I can use shuf
to shuffle the lines of a file. So I could use seq
to write random numbers to a file and then use shuf
to shuffle them — or write some sort of shuffle function. But this seems needlessly complex. Is there a simpler way to randomize the items in an array with a single command?
Best Answer
You can just pipe the output to
shuf
.Example
If you want the output to be horizontal then pipe it to
paste
.Want it with commas in between? Change the delimiter to
paste
: