Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!mcnc!rutgers!sunybcs!boulder!hao!oddjob!mimsy!umd5!brl-adm!adm!evh@vax1.acs.udel.EDU From: evh@vax1.acs.udel.EDU (SAVILLE) Newsgroups: comp.lang.c Subject: random ordering of lines........ Message-ID: <9530@brl-adm.ARPA> Date: Tue, 29-Sep-87 08:14:16 EDT Article-I.D.: brl-adm.9530 Posted: Tue Sep 29 08:14:16 1987 Date-Received: Wed, 30-Sep-87 07:01:42 EDT Sender: news@brl-adm.ARPA Lines: 65 Here is a random ordering that i wrote when i had nothing to do at 2:30am(EST). It consists of a c program and a shell script. Here is the c program: ---------cut here------------- #include #include #include #define rnd(l,h) ( (random() % (1+h-l)) + l) /*seed random# generator*/ void rndseed() { struct timeval tp; /* structure for time output defined in time.h */ struct timezone tzp; /* timezone...also defined in time.h */ gettimeofday(&tp,&tzp); srandom (tp.tv_sec * tp.tv_usec); } main() { char linebuff[2049]; rndseed(); while(gets(linebuff) != NULL) printf("%d@%s\n",rnd(50,1000),linebuff); } ---------cut here------------- # #Shell script for rsort program. #NOTE: change ./rsort to the path name of the c program # /bin/cat - | ./rsort | /usr/bin/sort -n | /bin/awk -F@ '{print $2}' ---------cut here------------- This worked for what little testing i did. The random# generations are not unique, but the sorting is random (if you call random() random). You could always keep track of what #'s you generated before....... evh@vax1.acs.udel.edu