#!/bin/csh -f #+ # irand -- generate a uniform random integer value between 0 and 32768 # # Purpose: # Returns a uniformly-distributed random integer between 0 and 32768, # using as a seed either the argument provided or, if none, the # Unix process number # # Usage: # irand [seed] # # Arguments: # seed = seed value for random number generator # # Exit values: # 0 = normal completion # 1 = wrong number of arguments # # Example: # 1) Return a random value: # punaluu{lris}186: ./irand # 21118 # punaluu{lris}187: ./irand # 6778 # Note that the values differ because the time of day (used # by default as the random generator's seed) changed. # # 2) Return a random value for a given seed: # punaluu{lris}190: ./irand 12345 # 16565 # punaluu{lris}191: ./irand 12345 # 16565 # Note that the values are the same when the same seed is used. #- # Modification history: # 2000-Jul-03 GDW Original version #----------------------------------------------------------------------- # parse command line args... if ( $#argv == 0 ) then @ seed = $$ # use process number else if ( $#argv == 1 ) then @ seed = $1 # use argument else echo "Usage: rand [seed]" exit 1 endif gawk "BEGIN{dum = srand(${seed}); \ print int(32768*rand())}"