39d2aca1601cac61e5507047fcf0802f4af5163a
[rrdtool.git] / src / rrd_utils.c
1 /**
2  * This program is free software; you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by the
4  * Free Software Foundation; only version 2 of the License is applicable.
5  *
6  * This program is distributed in the hope that it will be useful, but
7  * WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9  * General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
14  **/
15
16 #include "rrd_tool.h"
17
18 #include <stdlib.h>
19
20 #ifdef WIN32
21 #       define random() rand()
22 #       define srandom(x) srand(x)
23 #       define getpid() 0
24 #endif /* WIN32 */
25
26 /* make sure that the random number generator seeded EXACTLY ONCE */
27 long rrd_random(void)
28 {
29     static int rand_init = 0;
30     if (!rand_init) {
31         srandom((unsigned int) time(NULL) + (unsigned int) getpid());
32         rand_init++;
33     }
34
35     return random();
36 }