1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/common/random_engine.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/common/common.hpp"
12#include "duckdb/common/limits.hpp"
13#include "duckdb/common/mutex.hpp"
14
15#include <random>
16
17namespace duckdb {
18class ClientContext;
19struct RandomState;
20
21struct RandomEngine {
22 RandomEngine(int64_t seed = -1);
23 ~RandomEngine();
24
25public:
26 //! Generate a random number between min and max
27 double NextRandom(double min, double max);
28
29 //! Generate a random number between 0 and 1
30 double NextRandom();
31 uint32_t NextRandomInteger();
32
33 void SetSeed(uint32_t seed);
34
35 static RandomEngine &Get(ClientContext &context);
36
37 mutex lock;
38
39private:
40 unique_ptr<RandomState> random_state;
41};
42
43} // namespace duckdb
44