Random Numbers

   

Korn Shell: Unix and Linux Programming Manual, Third Edition, The
By Anatole Olczak

Table of Contents
Chapter 6.  Performing Arithmetic


The Korn shell provides a special variable, RANDOM, which is used to generate random numbers in the range from 0 to 32767. It generates a different random number each time it is referenced:

 $ print $RANDOM  27291  $ print $RANDOM  5386  $ print $RANDOM  6884 

You can also initialize a sequence of random numbers by setting RANDOM to a value. Here, RANDOM is set to 7. When subsequently accessed, the values 2726 and 18923 are returned:

 $ RANDOM=7  $ print $RANDOM  2726  $ print $RANDOM  18923 

When RANDOM is reset to 7 again, the same numbers are returned:

 $ RANDOM=7  $ print $RANDOM  2726  $ print $RANDOM  18923 

If RANDOM is unset, the special meaning is removed, even if reset.


       
    Top
     



    Korn Shell. Unix and Linux Programming Manual, Third Edition
    Korn Shell. Unix and Linux Programming Manual, Third Edition
    ISBN: N/A
    EAN: N/A
    Year: 2000
    Pages: 177

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net