## Random numbers

Random numbers
# 1
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

4. Seneca college, Toronto , Canada, peter wheeler, tech 154:

 edit by bakunin: Please have mercy! Instead of the 15 Pages of markup you used to create eye cancer in every reader simply use CODE-tags for your code. I cleaned that out for you, please don't make me do it again.

Last edited by bakunin; 03-25-2014 at 07:48 PM..
# 2
Where exactly are your difficulties, besides the single char typo? :P
Its a good start.
 sea View Public Profile for sea Find all posts by sea
# 3
problem with adding the two random numbers
i dont know what is the proper code to use
# 4
See: Man Page for bash (linux Section 1) - The UNIX and Linux Forums
Section: ARITHMETIC EVALUATION (c&p)

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

Last edited by sea; 03-26-2014 at 12:40 AM..
 sea View Public Profile for sea Find all posts by sea

Test Your Knowledge in Computers #786
Difficulty: Medium
In 2019, Bill Gates had a net worth estimated to be over \$200 billion USD.
True or False?

## How to insert random numbers into each line?

I have a file contains thousands of lines. I want to insert n random numbers into each line at specific position. Like this: 0 22…… 1 33…… …… …… I want to insert 3 random numbers from position 2 to 4 into each line. 0 325 22…… 1 685 33…… …… …… Please use CODE tags when...

## unique random numbers awk

Hi, I have a small piece of awk code (see below) that generates random numbers. gawk -F"," 'BEGIN { srand(); for (i = 1; i <= 30; i++) printf("%s AM329_%04d\n",\$0,int(36 * rand())+1) }' OFS=, AM329_hole_names.csv The code works fine and generates alphanumeric numbers like AM329_0001,...

## Random numbers in parent/child?

Hi I'm trying to generate random numbers both in parent process and the child process. But I get the same random number in both processes. Why doesn't it generate different numbers altough I seed random number generator? Here's my code: #include <stdio.h> #include <unistd.h> #include...

## Generating random numbers

Hi, I am having trouble with generating random numbers. can this be done with awk? So I have a file that looks like this: 23 30 24 40 26 34 So column1 is start and column2 is end. I want to generate 3 random #'s between start and stop: So the output will look like this: ...

## Random Numbers - Perl

Hi Guys I have a script to find Ranomd numbers. But I want to make the file to produce more random. Could u guys help me plz. In this Script I have the code that generates random in for loop and the range I have specified in my %chromlength input and out put will be like this chrno start end...

## Random NUmbers Generation with out repetation

Hi I have the below code MAXCOUNT=10 count=1 echo echo "\$MAXCOUNT random numbers:" echo "-----------------" while # Generate 10 (\$MAXCOUNT) random integers. do number=\$ + 1 ] "echo \$number" let "count += 1" # Increment count. done But aftre executing this ...

## Random numbers from 0 to 1000

Hello All, I want to make a simple script which generate random number from 0 to 1000. and simply display it. Plz HELP!!!!!! Regards, Waqas Ahmed

## How to set constrain on random numbers in c

Hi, I am currently trying to generate multiple random numbers in C for different variable:- die1=1+(rand()%5); die2=1+(rand()%5); die3=1+(rand()%5); die4=1+(rand()%5); But I need to contrain the total of die1, die2,die3 and die4 to be 5 as well. If i insert die1+die2+die3+die4=5, i do...

## Random numbers without repetition

Is anyone know some scripts to generate random number without repetition using bash; for example generate 10 different random numbers. Thanks