/* Copyright 2002 Mike Burns. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA The license is at . */ /* netgeek 2001-09-15 */ /* Mike Burns */ #include #include #include #define SNEAKERS 7 static char *colours[SNEAKERS] = {"red","orange","yellow","green","blue","khaki","black"}; static int set_sneakers (int date, int *sneakers); static int output (int date, int *sneakers); static int set_date (int argc, char **argv); static int current_date (void); int main (int argc, char **argv) { int date = set_date(argc, argv); int sneakers[2]; (void)set_sneakers(date, sneakers); (void)output(date,sneakers); return 0; } int set_sneakers (int date, int *sneakers) { /* modifies sneakers */ srand((unsigned int)date); sneakers[0] = (int)((SNEAKERS - 1.0) * rand() / RAND_MAX); sneakers[1] = (int)((SNEAKERS - 1.0) * rand() / RAND_MAX); if (sneakers[0] == sneakers[1]) { srand((unsigned int)(20.0 * rand())); sneakers[0] = (int)((SNEAKERS - 1.0) * rand() / RAND_MAX); sneakers[1] = (int)((SNEAKERS - 1.0) * rand() / RAND_MAX); } return 1; } int output (int date, int *sneakers) { (void)printf("Sneakers for %i: %s, %s\n", date, colours[sneakers[0]], colours[sneakers[1]]); return 1; } int set_date (int argc, char **argv) { if (argc > 1) return (int)strtod(argv[1],NULL); return current_date(); } int current_date (void) { struct tm *date; time_t t = time(NULL); if (t != -1) if ((date = localtime(&t)) != NULL) return (((1900+date->tm_year)*10000) + ((1+date->tm_mon)*100) + date->tm_mday); return 0; }