Skip to content

Instantly share code, notes, and snippets.

@jonquach
Created December 27, 2015 15:42
Show Gist options
  • Select an option

  • Save jonquach/380ad98e55902fe26f47 to your computer and use it in GitHub Desktop.

Select an option

Save jonquach/380ad98e55902fe26f47 to your computer and use it in GitHub Desktop.
Shell script for generating random number
#!/bin/bash
#This script accpets two integers as argv, and generate
#a random number between them included.
#Author: Jonathan Quach <kwach.yami@gmail.com>
if [ $# -ne 2 ]; then
echo -e "Usage:\t$0 [START END]"
exit
fi
DIFF=$(($2 - $1 + 1))
RANDOM=$$
R=$(($((RANDOM % $DIFF)) + $1))
echo $R
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment