aboutsummaryrefslogtreecommitdiff
path: root/bin/rnda
blob: 078e5008e774ea8d36deaaf9d21d34dac816b8f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh
# Choose a random argument using rndi(1)

# Check we have at least one argument
if [ "$#" -eq 0 ] ; then
    printf >&2 'rnda: No args given\n'
    exit 2
fi

# Get a random seed from rnds(1); if it's empty, that's still workable
seed=$(rnds)

# Get a random integet from 1 to the number of arguments
argi=$(rndi 1 "$#" "$seed") || exit

# Shift until that argument is the first argument
shift "$((argi-1))"

# Print it
printf '%s\n' "$1"