csnip  0.1
rng.h
Go to the documentation of this file.
1 #ifndef CSNIP_RNG_H
2 #define CSNIP_RNG_H
3 
12 struct csnip_rng_T {
13  unsigned long minval;
14  unsigned long maxval;
16  void* state;
20  void (*seed)(const struct csnip_rng_T* rng,
21  int nseed,
22  const unsigned long* seed);
24  unsigned long int (*getnum)(
25  const struct csnip_rng_T* rng);
26 };
27 
28 typedef struct csnip_rng_T csnip_rng;
29 
34 inline unsigned long int csnip_rng_getnum(const csnip_rng* R)
35 {
36  return (*R->getnum)(R);
37 }
38 
43 inline void csnip_rng_seed(const csnip_rng* R,
44  int nseed,
45  const unsigned long* seed)
46 {
47  (*R->seed)(R, nseed, seed);
48 }
49 
52 #endif /* CSNIP_RNG_H */
53 
54 #if defined(CSNIP_SHORT_NAMES) && !defined(CSNIP_RNG_HAVE_SHORT_NAMES)
55 #define rng csnip_rng
56 #define rng_getnum csnip_rng_getnum
57 #define rng_seed csnip_rng_seed
58 #define CSNIP_RNG_HAVE_SHORT_NAMES
59 #endif /* CSNIP_SHORT_NAMES && !CSNIP_RNG_HAVE_SHORT_NAMES */
unsigned long int csnip_rng_getnum(const csnip_rng *R)
Retrieve a number from the RNG.
Definition: rng.h:34
void csnip_rng_seed(const csnip_rng *R, int nseed, const unsigned long *seed)
Seed the RNG.
Definition: rng.h:43
Method table for a random number generator.
Definition: rng.h:12
unsigned long maxval
Maximum value returned by RNG, inclusive.
Definition: rng.h:14
void(* seed)(const struct csnip_rng_T *rng, int nseed, const unsigned long *seed)
Seed the RNG with the given seed memory.
Definition: rng.h:20
unsigned long int(* getnum)(const struct csnip_rng_T *rng)
Retrieve the next random number and update state.
Definition: rng.h:24
unsigned long minval
Minimum value returned by RNG, inclusive.
Definition: rng.h:13
void * state
The random number generator state.
Definition: rng.h:16