I have a function that selects a random object form an array. I have wrapped the internal bash function RANDOM, and implemented my function like that:
function rand() { echo $[ $RANDOM % $2 + $1 ]; }
function rand_obj() { objs=($@); index=$(rand 0 $#); echo ${objs[$index]} ; }
It works just fine, but I would love to learn a way of implementing it without the intermediate array objs. Any ideas? Thanks in advance
shift $(( $(rand 1 $#) - 1 )); echo "$1"?