7 /* sleep for randomized interval
9 /* #include <iostuff.h>
11 /* void rand_sleep(delay, variation)
13 /* unsigned variation;
15 /* rand_sleep() blocks the current process for an amount of time
16 /* pseudo-randomly chosen from the interval (delay +- variation/2).
20 /* Time to sleep in microseconds.
22 /* Variation in microseconds; must not be larger than delay.
24 /* Panic: interface violation. All system call errors are fatal.
28 /* The Secure Mailer license must be distributed with this software.
31 /* IBM T.J. Watson Research
33 /* Yorktown Heights, NY 10598, USA
43 /* Utility library. */
49 /* rand_sleep - block for random time */
51 void rand_sleep(unsigned delay
, unsigned variation
)
53 const char *myname
= "rand_sleep";
60 msg_panic("%s: bad delay %d", myname
, delay
);
61 if (variation
> delay
)
62 msg_panic("%s: bad variation %d", myname
, variation
);
65 * Use the semi-crappy random number generator.
67 usec
= (delay
- variation
/ 2) + variation
* (double) myrand() / RAND_MAX
;
73 #include <msg_vstream.h>
75 int main(int argc
, char **argv
)
80 msg_vstream_init(argv
[0], VSTREAM_ERR
);
82 msg_fatal("usage: %s delay variation", argv
[0]);
83 if ((delay
= atoi(argv
[1])) <= 0)
84 msg_fatal("bad delay: %s", argv
[1]);
85 if ((variation
= atoi(argv
[2])) < 0)
86 msg_fatal("bad variation: %s", argv
[2]);
87 rand_sleep(delay
* 1000000, variation
* 1000000);