ORE Studio 0.0.4
Loading...
Searching...
No Matches
generation_context.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_SYNTHETIC_DOMAIN_GENERATION_CONTEXT_HPP
21#define ORES_SYNTHETIC_DOMAIN_GENERATION_CONTEXT_HPP
22
23#include <array>
24#include <chrono>
25#include <cstdint>
26#include <random>
27#include <stdexcept>
28#include <string>
29#include <boost/uuid/uuid.hpp>
30
31namespace ores::synthetic::domain {
32
40class generation_context final {
41public:
47 explicit generation_context(std::uint64_t seed);
48
53
57 std::uint64_t seed() const { return seed_; }
58
62 int random_int(int min, int max);
63
67 bool random_bool(double probability = 0.5);
68
72 template<typename T>
73 const T& pick(const std::vector<T>& items) {
74 if (items.empty()) {
75 throw std::out_of_range("Cannot pick from an empty vector.");
76 }
77 std::uniform_int_distribution<std::size_t> dist(0, items.size() - 1);
78 return items[dist(engine_)];
79 }
80
84 template<typename T, std::size_t N>
85 const T& pick(const std::array<T, N>& items) {
86 static_assert(N > 0, "Cannot pick from an empty array.");
87 std::uniform_int_distribution<std::size_t> dist(0, N - 1);
88 return items[dist(engine_)];
89 }
90
94 boost::uuids::uuid generate_uuid();
95
99 std::chrono::system_clock::time_point past_timepoint(int years_back = 3);
100
104 std::string alphanumeric(std::size_t length);
105
106private:
107 std::uint64_t seed_;
108 std::mt19937_64 engine_;
109};
110
111}
112
113#endif
Context for controlling synthetic data generation.
Definition generation_context.hpp:40
std::string alphanumeric(std::size_t length)
Generates an alphanumeric string of specified length.
Definition generation_context.cpp:80
const T & pick(const std::array< T, N > &items)
Picks a random element from an array.
Definition generation_context.hpp:85
generation_context()
Constructs a generation context with a random seed.
Definition generation_context.cpp:27
bool random_bool(double probability=0.5)
Generates a random boolean with specified probability of true.
Definition generation_context.cpp:35
std::uint64_t seed() const
Returns the seed used for this context.
Definition generation_context.hpp:57
std::chrono::system_clock::time_point past_timepoint(int years_back=3)
Generates a random timestamp within the past N years.
Definition generation_context.cpp:74
const T & pick(const std::vector< T > &items)
Picks a random element from a vector.
Definition generation_context.hpp:73
int random_int(int min, int max)
Generates a random integer in the specified range.
Definition generation_context.cpp:30
boost::uuids::uuid generate_uuid()
Generates a UUID v7 based on the context's random state.
Definition generation_context.cpp:40