Debian Codegraph @

lib/util/random.h

raw
1 /// @file
2 /// @brief random number generation
3
4 #pragma once
5
6 #include <stdint.h>
7 #include <util/api.h>
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 /// generate a random permutation of the numbers `[0, bound - 1]`
14 ///
15 /// The caller is responsible for `free`ing the returned array. This function
16 /// calls `exit` on memory allocation failure.
17 ///
18 /// @param bound Exclusive upper bound on the sequence
19 /// @return A permutation of `[0, bound - 1]`
20 UTIL_API int *gv_permutation(int bound);
21
22 /// generate a random number in the range `[0, bound - 1]`
23 ///
24 /// This function assumes the caller has previously seeded the `rand` random
25 /// number generator.
26 ///
27 /// @param bound Exclusive upper bound on random number generation
28 /// @return A random number drawn from a uniform distribution
29 UTIL_API int gv_random(int bound);
30
31 /// generate a random 64-bit unsigned number in the range `[0, bound - 1]`
32 ///
33 /// This function assumes the caller has previously seeded the `rand` random
34 /// number generator.
35 ///
36 /// @param bound Exclusive upper bound on random number generation
37 /// @return A random number drawn from a uniform distribution
38 UTIL_API uint64_t gv_random_u64(uint64_t bound);
39
40 #ifdef __cplusplus
41 }
42 #endif