awk -v NUM=$1 -v TOPNUM=$2 ' # lotto - pick x random numbers out of y # main routine BEGIN { # test command line args; NUM = $1, how many numbers to pick # TOPNUM = $2, last number in series if (NUM <= 0) num=6 if (topnum <=0) topnum=30 # print "Pick x of y" printf("pick %d of %d\n", num, topnum) # seed random number using time and date; do this once srand() # loop until we have num selections for (j=1; j <=NUM; ++j) { # loop to find a not-yet-seen selection do { select=1 + int(rand() * topnum) } while (select in pick) pick[select]=select } # loop through array and print picks. for (j in pick) printf("%s ", pick[j])" printf("\n") }'>