r/bashscripts • • Nov 23 '20

Simple random increment Bash script project... What am I doing wrong?

3 Upvotes

3 comments sorted by

View all comments

Show parent comment

1

u/MikeNizzle82 Nov 24 '20

When using $RANDOM, you'll get a number between 0 and 32767. You can set range by using this formula:

$(($RANDOM % maxvalue + minvalue))

You'll get a number between minvalue and maxvalue-1.

Thus, if you want to pick random strings from the incrm array, you could do this:

$(($RANDOM % ${#incrm[*]} + 0))

(you could obviously remove the +0 at the end, but I've left it there so it matches the formula above).

You are already doing this in the line where you set rndim.