random numbers in a C shell script?

Longshot randy at uokmax.UUCP
Sat May 6 04:52:48 AEST 1989


In article <1501 at cmx.npac.syr.edu> gefuchs at logiclab.cis.syr.edu (Gill E. Fuchs) writes:
-
-Bon Jorno net,
-
-how would one go about getting a random numba in a C shell script?
-
-muchas randomas gracias

No way that I could find. I wrote this tiny prg to allow me to do it:


#include <stdio.h>
/*
	Return a random number between 1 and the argument given.
*/
main(argc,argv)
register int argc;
register char **argv;
{
	int i;
	long time(),random();

	srandom(time(0));
	i = atoi(*++argv);
	i = ((int)random() >> 4) % i;
	printf("%d\n",++i);
}

I use it to randomly select a .signature when I log in.

Randy
-- 
Randy J. Ray       University of Oklahoma, Norman, Oklahoma	(405)/325-5370
!texsun!uokmax!randy	randy at uokmax.uucp    randy at uokmax.ecn.uoknor.edu
"No one knows what it's like... to be the the bad man, to be the sad man..
behind blue eyes..."	-The Who



More information about the Comp.unix.questions mailing list