Random numbers

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

Write a shell script that will take the sum of two random number?
Ex: Random n1 +Random n2 = result

i tries to write it but i had some dufficulties

n=$RANDOM
# display a random integer <= 200
echo $(( r %= 200 ))
# display random number between 100 and 200.
echo $(( RANDOM % 200 + 100 ))
  1. Seneca college, Toronto , Canada, peter wheeler, tech 154:

Where exactly are your difficulties, besides the single char typo? :stuck_out_tongue:
Its a good start.

problem with adding the two random numbers
i dont know what is the proper code to use

See: Man Page for bash (linux Section 1) - The UNIX and Linux Forums
Section: ARITHMETIC EVALUATION (c&p)

And besides, you already have done adding two numbers.
See the generation of your 2nd random number.

However, i assume you ment, you dont know how to actualy work with the results?
You did set n=$RANDOM which means the variable $n now contains the value of $RANDOM , which is a (not a technical-term-ace) global variable, generating a random number between 0 and 32,7k.

Well, so you need to put that result, that is nicely packed as an expression $(( r %= 200 )) into a variable.
Lets call that variable NUM1 , so the (typo-corrected) code would look like NUM1=$(( n %= 200 )) .
You then can see the result by echo $NUM1 .

Then you can add the numbers using $NUM1 and $variable_b (as another example) instead.
NOTE: Variables are case sensitive and remain with their values in the shell until its exit.
Variables from scripts are not accessable from the shell unless the script exports them.

Hope this helps