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{
10
20float fast_hash32_to_unit_float(unsigned int seed, size_t k);
21
32uint64_t splitmix64(uint64_t x);
33
47float splitmix64_to_unit_float(unsigned int seed, size_t k);
48
61float uniform01(uint64_t h);
62
63// === PdfSampler class ===
64
69{
70public:
76 PdfSampler(const std::vector<float> &pdf, uint32_t seed);
77
82 float sample();
83
89 std::vector<float> sample(size_t nb_samples);
90
91private:
92 std::vector<float> cdf;
93 std::mt19937 generator;
94 std::uniform_real_distribution<float> distribution{0.f, 1.f};
95};
96
97} // namespace hmap
Samples indices from a discrete probability distribution.
Definition random.hpp:69
float sample()
Samples a float value in [0, 1[.
Definition pdf_sampler.cpp:33
Definition algebra.hpp:23
uint64_t splitmix64(uint64_t x)
Computes a deterministic 64-bit hash using the SplitMix64 algorithm.
Definition hash.cpp:19
float splitmix64_to_unit_float(unsigned int seed, size_t k)
Generates a deterministic uniform float in [0,1) from a seed and sample index.
Definition hash.cpp:27
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:10
float uniform01(uint64_t h)
Converts a 64-bit hash value into a deterministic uniform float in [0, 1).
Definition hash.cpp:44