random.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2013 Freie Universität Berlin
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
34 #include <inttypes.h>
35 #include <stddef.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #ifndef RANDOM_SEED_DEFAULT
46 #define RANDOM_SEED_DEFAULT (1)
47 #endif
48 
52 #ifndef PRNG_FLOAT
53 # define PRNG_FLOAT (0)
54 #endif
55 
68 void random_init(uint32_t s);
69 
79 void random_init_by_array(uint32_t init_key[], int key_length);
80 
85 uint32_t random_uint32(void);
86 
90 void random_bytes(void *buf, size_t size);
91 
102 uint32_t random_uint32_range(uint32_t a, uint32_t b);
103 
104 #if PRNG_FLOAT || defined(DOXYGEN)
105 /* These real versions are due to Isaku Wada, 2002/01/09 added */
106 
111 double random_real(void);
112 
118 
124 
129 double random_res53(void);
130 
131 #endif /* PRNG_FLOAT */
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 
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.