-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom.h
More file actions
35 lines (27 loc) · 1.04 KB
/
random.h
File metadata and controls
35 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef _OLIO_RANDOM_H_
#define _OLIO_RANDOM_H_
#include <inttypes.h>
typedef struct _olio_random {
uint32_t seed;
uint32_t state[627];
} olio_random;
#ifdef __cplusplus
extern "C" {
#endif
void olio_random_set_seed(olio_random *, uint32_t seed);
uint32_t olio_random_generate_seed(olio_random *);
uint32_t olio_random_integer(olio_random *); /* [0x0,0xffffffff] */
#ifdef __cplusplus
} /* extern C */
#endif
static inline uint32_t olio_random_get_seed(olio_random * r)
{ return r->seed; }
static inline double olio_random_real_ii(olio_random * r) /* [0,1] */
{ return (double) olio_random_integer(r) / 4294967295.0; }
static inline double olio_random_real_ie(olio_random * r) /* [0,1) */
{ return (double) olio_random_integer(r) / 4294967296.0; }
static inline double olio_random_real_ei(olio_random * r) /* (0,1] */
{ return ((double) olio_random_integer(r) + 1.0) / 4294967296.0; }
static inline double olio_random_real_ee(olio_random * r) /* (0,1) */
{ return ((double) olio_random_integer(r) + 0.5) / 4294967296.0; }
#endif /* _OLIO_RANDOM_H_ */