home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1564 / timemod.c < prev   
Encoding:
C/C++ Source or Header  |  1990-12-28  |  1.5 KB  |  45 lines

  1. /*
  2.     timemod.c -- Copyright 1990 Kent Paul Dolan, Mountain View, CA 94039-0755.
  3.  
  4.     Main program timemod accepts a strictly positive (long) integer from
  5.     the standard input.  Error checking is not performed on the input.
  6.  
  7.     It uses this integer as a modulus base MOD.
  8.  
  9.     Using the system time in seconds from time(3f), it performs the long
  10.     integer equivalent of "time() % MOD".
  11.  
  12.     It adds 1 to the result and writes a number in the range 1 to MOD to
  13.     the standard output.  
  14.  
  15.     Program timemod is useful for producing small "random" numbers during
  16.     interactive operations, for example to choose an element from a list
  17.     based on the (reasonably) random time when the user calls timemod.
  18.  
  19.     Timemod requires function time(3f), which can be in one of several
  20.     libraries depending on the site's OS and libraries.  At the developer's
  21.     site, it was found in /usr/lib/libc-nofp.a, and this program was
  22.     compiled using "cc -o timemod timemod.c -lc-nofp".
  23.  
  24.     Permission to use this program for any purpose except sale as part of
  25.     a commercial product, and to disseminate it so long as the source
  26.     including this credit comment is included with the executable, is
  27.     hereby granted by the author.
  28.  
  29.     As usual, this free software comes with no guarantees of useability, nor
  30.     does the author accept any liability for its use by others.
  31.  
  32. */
  33.  
  34. #include <stdio.h>
  35.  
  36. main ()
  37. {
  38.   long count,timehold,temp;
  39.   scanf("%ld",&count);
  40.   timehold = time();
  41.   temp = timehold/count;
  42.   printf("%ld\n",timehold - (temp*count) + 1);
  43.   exit (0);
  44. }
  45.