diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-08-27 09:20:39 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-08-27 09:20:39 +0200 |
commit | 2674577a6f147298f777ce740808a7cf625d6736 (patch) | |
tree | 3ab8dfefc23beb19502dce16a0804ab0140d8504 | |
parent | 841142b6f7c1c387be7538a12dbceca6f7b8f3d3 (diff) |
Minor code fixes
* seed random number generator with time [seconds] + PID instead of just
time [nanoseconds]
* Improve usage message
-rw-r--r-- | src/randsleep.c | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/randsleep.c b/src/randsleep.c index 46c6353..bf7bdc3 100644 --- a/src/randsleep.c +++ b/src/randsleep.c @@ -5,19 +5,15 @@ int main (int argc, char **argv) { long maxsleep; - struct timespec ntime; if (argc < 2) { - fputs("Usage: randsleep <max> [<cmd>]\n", stdout); + fputs("Usage: randsleep <max> [<cmd> [<args ...>]]\n", stderr); return 1; } maxsleep = atol(argv[1]); - if (clock_gettime(CLOCK_REALTIME, &ntime) == -1) - perror("clock_gettime"); - - srand(ntime.tv_nsec); + srand(time(NULL) + getpid()); sleep((rand() % maxsleep) + 1); |