A way to store 2 random numbers from a for loop?

I have a for loop that cycles twice and generates 1 random number for each pass through. I would like to be able to store the two numbers to use later for arithmetics. Is there a way to do that? Right now I can only seem to use the last random number for anything. Thanks.

# Clear the list of commandline parameters
set --

for X in 1 2
do
        # Add a random number to the end of the parameter list
        set -- "$@" "${RANDOM}"
done

echo "First number was $1"
echo "Second number was $2"

It's also possible to use arrays, but only in certain shells.

1 Like

Thanks. Is there a way to restrict the random numbers generated from say like 1-100?

Depends. What's your shell? $(((RANDOM%100)+1)) should work instead of ${RANDOM} for bash or ksh.

1 Like

I'm using Korn, which worked perfectly. Thanks again.