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 #pragma once
10 
37 #include <inttypes.h>
38 #include <stddef.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #ifndef RANDOM_SEED_DEFAULT
49 #define RANDOM_SEED_DEFAULT (1)
50 #endif
51 
55 #ifndef PRNG_FLOAT
56 # define PRNG_FLOAT (0)
57 #endif
58 
71 void random_init(uint32_t s);
72 
82 void random_init_by_array(uint32_t init_key[], int key_length);
83 
88 uint32_t random_uint32(void);
89 
93 void random_bytes(void *buf, size_t size);
94 
105 uint32_t random_uint32_range(uint32_t a, uint32_t b);
106 
107 #if PRNG_FLOAT || defined(DOXYGEN)
108 /* These real versions are due to Isaku Wada, 2002/01/09 added */
109 
114 double random_real(void);
115 
121 
127 
132 double random_res53(void);
133 
134 #endif /* PRNG_FLOAT */
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 
void random_init(uint32_t s)
initializes PRNG with a seed
double random_real_inclusive(void)
generates a random number on [0,1]-real-interval
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...
double random_res53(void)
generates a random number on [0,1) with 53-bit resolution
void random_bytes(void *buf, size_t size)
writes random bytes in the [0,0xff]-interval to memory
uint32_t random_uint32_range(uint32_t a, uint32_t b)
generates a random number r with a <= r < b.
uint32_t random_uint32(void)
generates a random number on [0,0xffffffff]-interval
double random_real(void)
generates a random number on [0,1)-real-interval
double random_real_exclusive(void)
generates a random number on (0,1)-real-interval
Adds include for missing inttype definitions.