Debian Codegraph @

Xpjproject/pjlib/include/pj/compat/rand.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #ifndef __PJ_COMPAT_RAND_H__
20 #define __PJ_COMPAT_RAND_H__
21
22 /**
23 * @file rand.h
24 * @brief Provides platform_rand() and platform_srand() functions.
25 */
26
27 #if defined(PJ_HAS_STDLIB_H) && PJ_HAS_STDLIB_H != 0
28 /*
29 * Use stdlib based rand() and srand().
30 */
31 # include <stdlib.h>
32 # define platform_srand srand
33 # if defined(RAND_MAX) && RAND_MAX <= 0xFFFF
34 /*
35 * When rand() is only 16 bit strong, double the strength
36 * by calling it twice!
37 */
38 PJ_INLINE(int) platform_rand(void)
39 {
40 return ((rand() & 0xFFFF) << 16) | (rand() & 0xFFFF);
41 }
42 # else
43 # define platform_rand rand
44 # endif
45
46 #else
47 # warning "platform_rand() is not implemented"
48 # define platform_rand() 1
49 # define platform_srand(seed)
50
51 #endif
52
53
54 #endif /* __PJ_COMPAT_RAND_H__ */
55