1

I need to set random even number as function parameter in terminal:
soapy_power -b random_even_number

First step, I generate random number with shuf -i1-10 -n1
Next,I try to judge whether random number is even,if not +1 to this number.

What I tried and failed: $(((shuf -i1-10 -n1) %2 -eq 0 OR (shuf -i1-10 -n1)+1))

How to generate random even number as parameter of function in bash one line command?

kittygirl
  • 2,255
  • 5
  • 24
  • 52
  • 1
    `$(( $(shuf -i1-5 -n1) * 2))`; though a solution referencing `$RANDOM` (eg, pjh's answer) eliminates the overhead of invoking a sub-process call – markp-fuso Mar 18 '22 at 19:34
  • Does this answer your question? [How to generate random number in Bash?](https://stackoverflow.com/questions/1194882/how-to-generate-random-number-in-bash) – Romeo Ninov Mar 19 '22 at 12:44

1 Answers1

1

Try

soapy_power -b "$(( RANDOM%5*2+2 ))"
pjh
  • 6,388
  • 2
  • 16
  • 17