libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
random.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <random>
11#include <cstdint>
12#include <cstddef>
14
16
17class Buffer;
18class Error;
19
41class Random {
42 public:
55 static Error trueRandom(uint8_t *buf, size_t bytes);
56
61 static Random &global();
62
67
72 explicit Random(uint64_t seed);
73
79
86 int randomInt(int min, int max);
87
95
102 double randomDouble(double min, double max);
103
110 float randomFloat(float min, float max);
111
117 Buffer randomBytes(size_t count);
118
124
125 private:
126 std::mt19937_64 _engine;
127};
128
Generic memory buffer descriptor with alignment and memory space support.
Definition buffer.h:85
Lightweight error code wrapper for the promeki library.
Definition error.h:39
Dynamic array container wrapping std::vector.
Definition list.h:40
Pseudo-random number generator wrapping std::mt19937_64.
Definition random.h:41
static Random & global()
Returns a thread-local global Random instance.
Random(uint64_t seed)
Constructs a Random with a specific seed.
double randomDouble(double min, double max)
Returns a uniformly distributed random double in [min, max).
Buffer randomBytes(size_t count)
Returns a Buffer filled with random bytes.
int randomInt(int min, int max)
Returns a uniformly distributed random integer in [min, max].
static Error trueRandom(uint8_t *buf, size_t bytes)
Fills a buffer with true random bytes from the OS entropy source.
int64_t randomInt64(int64_t min, int64_t max)
Returns a uniformly distributed random 64-bit integer in [min, max].
float randomFloat(float min, float max)
Returns a uniformly distributed random float in [min, max).
void seed(uint64_t seed)
Reseeds the engine.
bool randomBool()
Returns a random boolean with 50/50 probability.
Random()
Constructs a Random seeded from std::random_device.
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19