Build fix: missing operator- for iterator on g++7
[lttng-tools.git] / src / common / random.hpp
CommitLineData
57b90af7
JG
1/*
2 * Copyright (C) 2023 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8#ifndef LTTNG_RANDOM_H
9#define LTTNG_RANDOM_H
10
11#include "exception.hpp"
12
13#include <cstddef>
14#include <string>
15
16namespace lttng {
17namespace random {
18
19using seed_t = unsigned int;
20
21class production_error : public ::lttng::runtime_error {
22public:
23 explicit production_error(const std::string& msg,
28f23191
JG
24 const char *file_name,
25 const char *function_name,
26 unsigned int line_number);
57b90af7
JG
27};
28
29/*
30 * Get a seed from a reliable source of randomness without blocking, raising
31 * an exception on failure.
32 */
33seed_t produce_true_random_seed();
34
35/*
36 * Get a random seed making a best-effort to use a true randomness source,
37 * but falling back to a pseudo-random seed based on the time and various system
38 * configuration values on failure.
39 *
40 * Note that this function attempts to use the urandom device, which will block
41 * in the unlikely event that its pool is uninitialized, on platforms that don't
42 * provide getrandom().
43 */
44seed_t produce_best_effort_random_seed();
45
46} /* namespace random */
47} /* namespace lttng */
48
49#endif /* LTTNG_RANDOM_H */
This page took 0.036602 seconds and 4 git commands to generate.