Monday, June 3, 2013

Command Line Magic - Pick A Random Number From Your Given Range

One day my friend told me that what to do to pick a random number form desired range. I told there are many algorithms infact you can create your own C program for that just 10 to 15 lines of code.

He told I don't know the syntax of C so can you find something else for that. Then I played with Ubuntu terminal and created command.

Initially I was searching for any command for terminal which can give me random link. But I was unable to find. Then I got this link on internet.


As mentioned $(( EXPRESSION ))  allows the evaluation of an arithmetic expression and the substitution of the result. The format for arithmetic expansion is:

Then I made this command and gave to terminal.

#  echo $((RANDOM % 99)) 

 


Whenever you will run this command, It will give you random number every time between 0 to 99.

No comments: