Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwvax!tank!eecae!netnews.upenn.edu!jes From: jes@mbio.med.upenn.edu (Joe Smith) Newsgroups: comp.unix.questions Subject: Re: How do I pick a word at random from a list of words? Message-ID: Date: 20 May 89 01:10:59 GMT References: <19669@adm.BRL.MIL> Sender: news@netnews.upenn.edu Organization: University of Pennsylvania, Philadelphia, PA Lines: 23 In-reply-to: bjornand@idt.unit.no's message of 18 May 89 16:36:22 GMT At the risk of starting a 'lets all write this in our favorite langauge' blitz, here's an awk (sorry, 'new' awk or GNU awk) function that print's an argument at random. It's easily modified to read a file of words, if you need that. ------------------------------>8 cut here 8<------------------------------ #!/bin/sh gawk ' BEGIN { srand() # set rand() seed from current time print rword(ARGV, ARGC) exit } function rword (a, n) { return a[ int(rand() * n + 1) ] # 1 <= n <= ARGC }' $* -- Joe Smith University of Pennsylvania jes@mbio.med.upenn.edu Dept. of Biochemistry and Biophysics (215) 898-8348 Philadelphia, PA 19104-6059