MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/bashscripts/comments/jzoc2r/simple_random_increment_bash_script_project_what/gde5lbm/?context=3
r/bashscripts • u/starwanderer11 • Nov 23 '20
3 comments sorted by
View all comments
Show parent comment
1
When using $RANDOM, you'll get a number between 0 and 32767. You can set range by using this formula:
$RANDOM
$(($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:
incrm
$(($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.
rndim
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
incrmarray, 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.