#!/bin/csh -f #+ # rand -- generate a uniform random value between 0 and 1 # # Purpose: # Returns a uniformly-distributed random number between 0 and 1, # using as a seed either the argument provided or, if none, the # Unix process number # # Usage: # rand [seed] # # Arguments: # seed = seed value for random number generator # # Example: # 1) Return a random value: # punaluu{lris}165: rand # 0.791128 # punaluu{lris}162: ./rand # 0.228747 # Note that the values differ because the process number (used # by default as the random generator's seed) changed. # # 2) Return a random value for a given seed: # punaluu{lris}167: ./rand 12345 # 0.505545 # punaluu{lris}168: ./rand 12345 # 0.505545 # 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 Unix 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 rand()}"