No empty .Rs/.Re
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / util / myrand.c
blob0a786b4652a253fb440edb8e61f86ee61c773367
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* myrand 3
6 /* SUMMARY
7 /* rand wrapper
8 /* SYNOPSIS
9 /* #include <myrand.h>
11 /* void mysrand(seed)
12 /* int seed;
14 /* int myrand()
15 /* DESCRIPTION
16 /* This module implements a wrapper for the portable, pseudo-random
17 /* number generator. The wrapper adds automatic initialization.
19 /* mysrand() performs initialization. This call may be skipped.
21 /* myrand() returns a pseudo-random number in the range [0, RAND_MAX].
22 /* If mysrand() was not called, it is invoked with the process ID
23 /* ex-or-ed with the time of day in seconds.
24 /* LICENSE
25 /* .ad
26 /* .fi
27 /* The Secure Mailer license must be distributed with this software.
28 /* WARNING
29 /* Do not use this code for generating unpredictable numbers.
30 /* AUTHOR(S)
31 /* Wietse Venema
32 /* IBM T.J. Watson Research
33 /* P.O. Box 704
34 /* Yorktown Heights, NY 10598, USA
35 /*--*/
37 /* System library. */
39 #include <sys_defs.h>
40 #include <stdlib.h>
41 #include <unistd.h>
42 #include <time.h>
44 /* Utility library. */
46 #include <myrand.h>
48 static int myrand_initdone = 0;
50 /* mysrand - initialize */
52 void mysrand(int seed)
54 srand(seed);
55 myrand_initdone = 1;
58 /* myrand - pseudo-random number */
60 int myrand(void)
62 if (myrand_initdone == 0)
63 mysrand(getpid() ^ time((time_t *) 0));
64 return (rand());