home *** CD-ROM | disk | FTP | other *** search
- /*
- timemod.c -- Copyright 1990 Kent Paul Dolan, Mountain View, CA 94039-0755.
-
- Main program timemod accepts a strictly positive (long) integer from
- the standard input. Error checking is not performed on the input.
-
- It uses this integer as a modulus base MOD.
-
- Using the system time in seconds from time(3f), it performs the long
- integer equivalent of "time() % MOD".
-
- It adds 1 to the result and writes a number in the range 1 to MOD to
- the standard output.
-
- Program timemod is useful for producing small "random" numbers during
- interactive operations, for example to choose an element from a list
- based on the (reasonably) random time when the user calls timemod.
-
- Timemod requires function time(3f), which can be in one of several
- libraries depending on the site's OS and libraries. At the developer's
- site, it was found in /usr/lib/libc-nofp.a, and this program was
- compiled using "cc -o timemod timemod.c -lc-nofp".
-
- Permission to use this program for any purpose except sale as part of
- a commercial product, and to disseminate it so long as the source
- including this credit comment is included with the executable, is
- hereby granted by the author.
-
- As usual, this free software comes with no guarantees of useability, nor
- does the author accept any liability for its use by others.
-
- */
-
- #include <stdio.h>
-
- main ()
- {
- long count,timehold,temp;
- scanf("%ld",&count);
- timehold = time();
- temp = timehold/count;
- printf("%ld\n",timehold - (temp*count) + 1);
- exit (0);
- }
-