random.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 
26 #ifndef RANDOM_H
27 #define RANDOM_H
28 
29 #include <inttypes.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #ifndef RANDOM_SEED_DEFAULT
36 
40 #define RANDOM_SEED_DEFAULT (1)
41 #endif
42 
46 #ifndef PRNG_FLOAT
47 # define PRNG_FLOAT (0)
48 #endif
49 
59 void random_init(uint32_t s);
60 
70 void random_init_by_array(uint32_t init_key[], int key_length);
71 
76 uint32_t random_uint32(void);
77 
88 static inline uint32_t random_uint32_range(uint32_t a, uint32_t b)
89 {
90  return (random_uint32() % (b - a)) + a;
91 }
92 
93 #if PRNG_FLOAT
94 /* These real versions are due to Isaku Wada, 2002/01/09 added */
95 
100 double random_real(void);
101 
106 double random_real_inclusive(void);
107 
112 double random_real_exclusive(void);
113 
118 double random_res53(void);
119 
120 #endif /* PRNG_FLOAT */
121 
122 #ifdef __cplusplus
123 }
124 #endif
125 
126 #endif /* RANDOM_H */
127 
static uint32_t random_uint32_range(uint32_t a, uint32_t b)
generates a random number r with a <= r < b.
Definition: random.h:88
void random_init_by_array(uint32_t init_key[], int key_length)
initialize by an array with array-length init_key is the array for initializing keys key_length is it...
Adds include for missing inttype definitions.
void random_init(uint32_t s)
initializes PRNG with a seed
uint32_t random_uint32(void)
generates a random number on [0,0xffffffff]-interval