I have been futzing about learning bash tonight and I have been trying to create a random number sequence that uses all the numbers of a range and uses each digit just once. So something like inputting the range of 1-5 will output something like 4-3-5-2-1 or 2-5-1-3-4 and so on. I am as stuck as can be on this one.
Thanks!
the following command is not specific to bash, but it worked
seq 1 5 | shuf
a more bash specific with substrings
x=12345
for((i=5;i>0;i--));do
((r=RANDOM%i+1))
echo ${x:r-1:1}
x=${x:0:r-1}${x:r}
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With