Home > other >  How To Generate a Random Number that is a multiple 3 in a Range in a Bash Script?
How To Generate a Random Number that is a multiple 3 in a Range in a Bash Script?

Time:05-11

I apologize if my title question is too broad. I am trying to generate a variable that is a random multiple of 3 between a certain range.

randomNumber= Multiple of 3 between 45 and 72

CodePudding user response:

Bash has a builtin RANDOM var. (There's also SRANDOM if you have Bash 5.1 )

[Bash-5.2] % echo $(( 3 * (15   RANDOM % 10) ))
51
[Bash-5.2] % echo $(( 3 * (15   RANDOM % 10) ))
57
[Bash-5.2] % echo $(( 3 * (15   RANDOM % 10) ))
48
  • Related