Debian Codegraph @

lib/util/randsysrandom.c

raw
1 /* Implementation note: Mingw/Windows does not provide POSIX 'random', so
2 netpbm/pm_config.h makes that a macro for POSIX 'rand' on that platform
3 */
4
5 #define _DEFAULT_SOURCE /* New name for SVID & BSD source defines */
6 #define _XOPEN_SOURCE 500 /* Make sure random() is in stdlib.h */
7 #define _BSD_SOURCE /* Make sure random() is in stdlib.h */
8
9 #include <stdlib.h>
10
11 #include "netpbm/pm_config.h"
12 #include "netpbm/rand.h"
13
14 static void
15 vinit(struct pm_randSt * const randStP) {
16
17 randStP->max = RAND_MAX;
18 randStP->stateP = NULL;
19 }
20
21
22
23 static void
24 vsrand(struct pm_randSt * const randStP,
25 unsigned int const seed) {
26
27 srandom(seed);
28 }
29
30
31
32 static unsigned long int
33 vrand(struct pm_randSt * const randStP) {
34
35 return random();
36 }
37
38
39 struct pm_rand_vtable const pm_randsysrandom_vtable = {
40 &vinit,
41 &vsrand,
42 &vrand
43 };
44
45