HighMap library (C++)
Loading...
Searching...
No Matches
random.hpp
Go to the documentation of this file.
1/* Copyright (c) 2026 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4#pragma once
5#include <cstddef>
6#include <cstdint>
7
8namespace hmap
9{
19float fast_hash32_to_unit_float(unsigned int seed, size_t k);
20
29float splitmix64_to_unit_float(unsigned int seed, size_t k);
30
31// === PdfSampler class ===
32
37{
38public:
44 PdfSampler(const std::vector<float> &pdf, uint32_t seed);
45
50 float sample();
51
57 std::vector<float> sample(size_t nb_samples);
58
59private:
60 std::vector<float> cdf;
61 std::mt19937 generator;
62 std::uniform_real_distribution<float> distribution{0.f, 1.f};
63};
64
65} // namespace hmap
Samples indices from a discrete probability distribution.
Definition random.hpp:37
float sample()
Samples a float value in [0, 1[.
Definition pdf_sampler.cpp:33
Definition algebra.hpp:23
float splitmix64_to_unit_float(unsigned int seed, size_t k)
Generates a deterministic uniform float in [0,1) using a SplitMix64-style hash.
Definition hash.cpp:10
float fast_hash32_to_unit_float(unsigned int seed, size_t k)
Generates a fast deterministic uniform float in [0,1) using a 32-bit hash.
Definition hash.cpp:27