blob: efd2527a355ff25a9065a6fb534285183b56ce8d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static unsigned int hash(const void* key, size_t size) {
const char* ptr = key;
unsigned int hval;
for (hval = 0x811c9dc5u; size --> 0; ++ptr) {
hval ^= *ptr;
hval *= 0x1000193u;
}
return hval;
}
static inline int roll(int sides) {
return rand() / (RAND_MAX + 1.0) * sides;
}
int main(int argc, const char* argv[]) {
int rc, delay;
time_t now = time(0);
/* initialize the random number generator */
srand(hash(&now, sizeof(now)));
/* determine exit code and time delay */
switch (argc) {
default:
delay = atoi(argv[1]);
rc = atoi(argv[2]);
break;
case 2:
delay = atoi(argv[1]);
rc = roll(2) - 1;
break;
case 1:
delay = roll(10);
rc = roll(2) - 1;
break;
}
printf("Delay: %ds, Exit Code: %d\n", delay, rc);
fflush(stdout);
sleep(delay);
return rc;
}
|