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 
27 #ifndef RANDOM_H
28 #define RANDOM_H
29 
30 #include <inttypes.h>
31 #include <stddef.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #ifndef RANDOM_SEED_DEFAULT
38 
42 #define RANDOM_SEED_DEFAULT (1)
43 #endif
44 
48 #ifndef PRNG_FLOAT
49 # define PRNG_FLOAT (0)
50 #endif
51 
61 void random_init(uint32_t s);
62 
72 void random_init_by_array(uint32_t init_key[], int key_length);
73 
78 uint32_t random_uint32(void);
79 
83 void random_bytes(uint8_t *buf, size_t size);
84 
95 static inline uint32_t random_uint32_range(uint32_t a, uint32_t b)
96 {
97  return (random_uint32() % (b - a)) + a;
98 }
99 
100 #if PRNG_FLOAT
101 /* These real versions are due to Isaku Wada, 2002/01/09 added */
102 
107 double random_real(void);
108 
113 double random_real_inclusive(void);
114 
119 double random_real_exclusive(void);
120 
125 double random_res53(void);
126 
127 #endif /* PRNG_FLOAT */
128 
129 #ifdef __cplusplus
130 }
131 #endif
132 
133 #endif /* RANDOM_H */
134 
static uint32_t random_uint32_range(uint32_t a, uint32_t b)
generates a random number r with a <= r < b.
Definition: random.h:95
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
void random_bytes(uint8_t *buf, size_t size)
writes random bytes in the [0,0xff]-interval to memory