Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
RandomSource.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
3#pragma once
4
19
20#include <chrono>
21#include <random>
22#include <string_view>
23
24#include "Types.hpp"
25#include "Hash.hpp"
26
27namespace esengine {
28
30public:
32 : root_(static_cast<u32>(std::chrono::steady_clock::now().time_since_epoch().count())) {}
33
34 explicit RandomSource(u32 root) : root_(root) {}
35
37 void reseed(u32 root) { root_ = root; }
38
39 u32 root() const { return root_; }
40
42 std::mt19937 stream(std::string_view name) const {
43 return std::mt19937(hash::fnv1a32(name) ^ root_);
44 }
45
46private:
47 u32 root_;
48};
49
55void setPendingRandomSeed(u32 seed);
57bool takePendingRandomSeed(u32& out);
58
59} // namespace esengine
Core type definitions and utilities for ESEngine.
std::mt19937 stream(std::string_view name) const
constexpr u32 fnv1a32(std::string_view text)
Definition Hash.hpp:27
bool takePendingRandomSeed(u32 &out)
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
void setPendingRandomSeed(u32 seed)