aboutsummaryrefslogblamecommitdiff
path: root/bin/rndi.awk
blob: 337498cb2c7f39af6870fc603e966632ca214a23 (plain) (tree)
1
2
3
4
5
6
7
8
9
10


                                                                               
 
       

                                           


                      

                                                                       


               

                                                                      
                                                 

                                      

        
# Get a low-quality random number between two integers. Depending on the awk
# implementation, if you don't provide a third argument (a seed), you might get
# very predictable random numbers based on the current epoch second.

BEGIN {

    # Seed with the third argument if given
    if (ARGV[3]) {
        srand(ARGV[3])
    }

    # If not, just seed with what is probably a date/time-derived value
    else {
        srand()
    }

    # Print a random integer bounded by the first and second arguments
    print int(ARGV[1]+rand()*(ARGV[2]-ARGV[1]+1))

    # Bail before processing any lines
    exit
}