lnx1 1> make tdrand48
pgf77 -g -c tdrand48.f
pgf77 -g -L/usr/local/PGI/lib tdrand48.o -lp410f -o tdrand48

lnx1 2> tdrand48
 usage: trand <n> [<seed>]

############################################################
# Generate 10 random numbers using the default seed.
############################################################
lnx1 3> tdrand48 10
   3.9079850466805510E-014
   9.8539467465030839E-004
   4.1631001594613082E-002
   0.1766426425429160     
   0.3646022483906073     
   9.1330612112294318E-002
   9.2297647698675434E-002
   0.4872172239468284     
   0.5267502797621084     
   0.4544334237382444     

 Average:   0.2235890474460977     

############################################################
# Use different seeds ...
############################################################
lnx1 4> tdrand48 10 0
   0.1708280361062897     
   0.7499019804849638     
   9.6371655623567420E-002
   0.8704652270270756     
   0.5773035067951078     
   0.7857992588396741     
   0.6921941534586402     
   0.3687662699204211     
   0.8739040768618089     
   0.7450950984500651     

 Average:   0.5930629263567614     
lnx1 5> tdrand48 10 1024
   0.8723921096689118     
   0.2505373659982695     
   0.2646277000113848     
   0.5637676199866704     
   0.4796618003284330     
   0.9366764961596203     
   0.9770464197702857     
   0.9566037275772814     
   0.5051937973970873     
   0.8319197539829020     

 Average:   0.6638426790880846     

############################################################
# Use a csh foreach loop to investigate the large-n limit 
# of the average of the generated numbers.  Also note 
# the use of the Unix 'time' command to report the CPU time 
# usage (and other statistics, see 'man time') of an 
# arbitrary command.
############################################################
lnx1 7> foreach n (10 100 1000 10000 100000 1000000)
foreach? time tdrand48 $n > /dev/null
foreach? end

 Average:   0.2235890474460977     
0.000u 0.000s 0:00.00 0.0%      0+0k 0+0io 119pf+0w

 Average:   0.4741044494625102     
0.000u 0.010s 0:00.00 0.0%      0+0k 0+0io 119pf+0w 

 Average:   0.4914224988159484     
0.010u 0.000s 0:00.01 100.0%    0+0k 0+0io 119pf+0w 

 Average:   0.4988303692558301     
0.100u 0.010s 0:00.10 110.0%    0+0k 0+0io 119pf+0w

 Average:   0.4995105666942632     
1.030u 0.000s 0:01.02 100.9%    0+0k 0+0io 119pf+0w

 Average:   0.4997852648772501     
10.270u 0.070s 0:11.17 92.5%    0+0k 0+0io 119pf+0w

############################################################
# Note that in this case, particularly for large values 
# of n, the execution time is completely dominated by the
# formatted output to standard output.  EXERCISE: Repeat
# the timing test using a modified version of 'tdrand48' 
# that does NOT output the random numbers to standard 
# output, but which still outputs the average value of the 
# generated iterates to standard error.
############################################################