Generate random numbers in bash

Bash provides a way to generate random numbers using RANDOM environment variable each time this variable is referenced a random integer between 0 to 32767 is generated.

[root@localhost ~]# echo $RANDOM
23495

if you want to list all environment in linux type $ and press tab twice it will display all environment variables.

[root@localhost ~]# $
$_                          $CVS_RSH                    $LINENO                     $QTLIB
$APPL_PATH                  $DIRSTACK                   $LINES                      $RANDOM
$APP_PH_LIC                 $DISPLAY                    $LOGNAME                    $SECONDS
$BASH                       $EUID                       $LS_COLORS                  $SELINUX_LEVEL_REQUESTED
$BASH_ALIASES               $G_BROKEN_FILENAMES         $MACHTYPE                   $SELINUX_ROLE_REQUESTED
$BASH_ARGC                  $GROUPS                     $MAIL                       $SELINUX_USE_CURRENT_RANGE
$BASH_ARGV                  $HISTCMD                    $MAILCHECK                  $SHELL
$BASH_CMDS                  $HISTCONTROL                $OPTERR                     $SHELLOPTS
$BASH_COMMAND               $HISTFILE                   $OPTIND                     $SHLVL
$BASH_LINENO                $HISTFILESIZE               $OSTYPE                     $SS7_PH_LIC
$BASHOPTS                   $HISTSIZE                   $PATH                       $SS7P_PATH
$BASHPID                    $HOME                       $PIPESTATUS                 $SSH_ASKPASS
$BASH_SOURCE                $HOSTNAME                   $PPID                       $SSH_CLIENT
$BASH_SUBSHELL              $HOSTTYPE                   $PROMPT_COMMAND             $SSH_CONNECTION
$BASH_VERSINFO              $ID                         $PS1                        $SSH_TTY
$BASH_VERSION               $IFS                        $PS2                        $TERM
$colors                     $JAVA_HOME                  $PS4                        $UID
$COLORS                     $LANG                       $PWD                        $USER
$COLUMNS                    $LD_LIBRARY_PATH            $QTDIR
$COMP_WORDBREAKS            $LESSOPEN                   $QTINC
[root@localhost ~]# $
Advertisements
This entry was posted in Linux. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s