I think the script below does the sort of thing you want. This script uses a separate file with the list of possible symlink targets, but it illustrates how to use bash's built in variable $RANDOM to do the selection.
$RANDOM is automatically seeded when bash is invoked by (I believe) the sum of the system time and the PID. I imagine this is good enough for your purposes. If you wanted to get fancier, you could either seed $RANDOM using /dev/urandom
or use the output of /dev/urandom
(one or two bytes worth, probably) directly for your random number.
As the comments indicate, I wasn't trying to anticipate all possible faults or allow for a fancy $TARGETS file, so feel free to flesh it out as you wish. And of course, change the definitions of TARGETS and LINK to suit your needs.
# Script to randomly select a line from the $TARGETS file as the target
# for a symbolic link named $LINK.
# $TARGETS must contain one valid path/file (no spaces) on each line with
# no other lines present.
# This is a quick-n-dirty script with almost no sanity testing or decent
# error reporting.
[ ! -s $TARGETS ] && exit
count=$(cat $TARGETS | wc -l | tr -d " ")
[ $count -eq 0 ] && exit
index=$((($RANDOM % $count) + 1))
dest=$(head -n $index $TARGETS | tail -n 1)
[ "$1" == -v ] && echo "Creating symlink $LINK -> $dest"
ln -sf $dest $LINK
In case I wasn't clear, the $TARGETS file has the following form: