[comp.lang.c] random ordering of lines........

evh@vax1.acs.udel.EDU (SAVILLE) (09/29/87)

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 <stdio.h>
#include <sys/types.h>
#include <sys/time.h>

#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