Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!spool.mu.edu!uwm.edu!linac!att!cbnews!cbnewsl!urban From: urban@cbnewsl.att.com (john.urban) Newsgroups: comp.unix.questions Subject: Re: random numbers in awk? Keywords: nawk Message-ID: <1991Apr24.133711.29958@cbnewsl.att.com> Date: 24 Apr 91 13:37:11 GMT Article-I.D.: cbnewsl.1991Apr24.133711.29958 References: <26019@adm.brl.mil> <1991Apr24.041134.14519@athena.mit.edu> Distribution: usa Organization: AT&T Bell Laboratories Lines: 38 > article <26019@adm.brl.mil>, d3e608%pnli.pnl.gov@pnlg.pnl.gov writes: > I'm trying to write a csh script to extract a random multiline > record from a file. Awk does a nice job of getting the records. Now how Several version of UNIX System V have nawk (new awk). Regular awk does not have the rand() function however nawk does. To see if you version of UNIX has nawk, type in: $ type nawk If you've got nawk, then you can do something like: nawk 'BEGIN {print rand()}' < /dev/null to get a random number on the screen UNIX System V/386 Release 3.2 (and higher) also have the random(1) command [Part of the XENIX System V and UNIX System V/386 merged product] So you could use: random(1) although it doesn't appear to be total random. I tried: $ i=100 $ while [ $i -gt 0 ] > do > random 10 > i=`expr $i - 1` > done | sort -n | uniq -c 25 0 10 4 38 5 3 6 24 10 Sincerely, John Urban