🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #770

Re: random i/o

#770
From: Dave Decot
Date: Wed, 29 Nov 1989 23:09
37 lines
1028 bytes
For BSD or HP-UX systems, here's select.c:

    #include <stdio.h>
    #include <time.h>

    main(argc, argv)
    int argc;
    char *argv[];
    {
	char s[80];
	struct timeval t;
	int i, j;

	    gettimeofday(&t, 0);
	    j = srand(t.tv_usec);

	    freopen(argv[2], "r", stdin);

	    gets(s);

	    i = rand() % atoi(argv[1]) - 1;

	    while(i-- > 0)
		gets(s);
	    
	    puts(s);
    }

Usage:

    select `wc -l inputfile` inputfile

For systems without gettimeofday() or some other rapidly changing value,
you will have to find some other means of seeding the generator.

Dave Decot
Hewlett-Packard Company
Technical Details
Message-ID: <13540005@hpisod2.HP.COM>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!ucsdhub!hp-sdd!hplabs!hpda!hpcupt1!hpisod2!decot
References: <111@lkbpyr.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!ucsdhub!hp-sdd!hplabs!hpda!hpcupt1!hpisod2!decot
From: decot@hpisod2.HP.COM (Dave Decot)
Newsgroups: comp.lang.misc
Subject: Re: random i/o
Message-ID: <13540005@hpisod2.HP.COM>
Date: 29 Nov 89 23:09:33 GMT
References: <111@lkbpyr.UUCP>
Organization: Hewlett Packard, Cupertino
Lines: 37