#!/bin/sh # @(#) random - Revision 1.1 - 01/28/97 # # ============================================================================= # Andrea Whitlock, Mobius Software Services # whitlock@mobius-soft.com # # Bug reports, questions, and suggestions should be emailed to: # mobius@mobius-soft.com # # This software is provided under the terms of the GNU copyleft # (ftp://prep.ai.mit.edu/pub/gnu/COPYING-2.0), without a warranty # of any kind. Use at your own risk. # ============================================================================= # # configure me ################################################################ # your awk needs to support rand() and needs to be able to deal with a # variable field width or precision in printf (i.e. printf "%*d", width, num). #AWK=awk #AWK=gawk AWK=nawk # configure me ################################################################ if [ ! "$1" ] then digits=8 # default else digits=$1 fi echo $digits | $AWK '{ digits = $0 srand(seed) num = sprintf("1%0*d", digits, 0) - 1 randomnum = int(rand() * num) printf("%0*d\n", digits, randomnum) }' seed=$$