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 #include <stddef.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #ifndef RANDOM_SEED_DEFAULT
37 
41 #define RANDOM_SEED_DEFAULT (1)
42 #endif
43 
47 #ifndef PRNG_FLOAT
48 # define PRNG_FLOAT (0)
49 #endif
50 
60 void random_init(uint32_t s);
61 
71 void random_init_by_array(uint32_t init_key[], int key_length);
72 
77 uint32_t random_uint32(void);
78 
82 void random_bytes(uint8_t *buf, size_t size);
83 
94 static inline uint32_t random_uint32_range(uint32_t a, uint32_t b)
95 {
96  return (random_uint32() % (b - a)) + a;
97 }
98 
99 #if PRNG_FLOAT
100 /* These real versions are due to Isaku Wada, 2002/01/09 added */
101 
106 double random_real(void);
107 
112 double random_real_inclusive(void);
113 
118 double random_real_exclusive(void);
119 
124 double random_res53(void);
125 
126 #endif /* PRNG_FLOAT */
127 
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif /* RANDOM_H */
133 
static uint32_t random_uint32_range(uint32_t a, uint32_t b)
generates a random number r with a <= r < b.
Definition: random.h:94
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