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#include <random>
8#include <vector>
9
10namespace hmap
11{
12
22float fast_hash32_to_unit_float(unsigned int seed, size_t k);
23
32float hash01(uint32_t a, uint32_t b);
33
40uint32_t hash32(uint32_t x);
41
52uint64_t splitmix64(uint64_t x);
53
67float splitmix64_to_unit_float(unsigned int seed, size_t k);
68
81float uniform01(uint64_t h);
82
91float vnoise(float x, float y, uint32_t seed = 0);
92
93// === PdfSampler class ===
94
99{
100public:
106 PdfSampler(const std::vector<float> &pdf, uint32_t seed);
107
112 float sample();
113
119 std::vector<float> sample(size_t nb_samples);
120
121private:
122 std::vector<float> cdf;
123 std::mt19937 generator;
124 std::uniform_real_distribution<float> distribution{0.f, 1.f};
125};
126
127} // namespace hmap
float sample()
Samples a float value in [0, 1[.
Definition pdf_sampler.cpp:33
PdfSampler(const std::vector< float > &pdf, uint32_t seed)
Builds the sampler from a PDF and seed.
Definition pdf_sampler.cpp:17
Definition opencv.hpp:20
uint64_t splitmix64(uint64_t x)
Computes a deterministic 64-bit hash using the SplitMix64 algorithm.
Definition hash.cpp:37
uint32_t hash32(uint32_t x)
Integer hash function (Murmur3 / finalize style 32-bit mixer).
Definition hash.cpp:27
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:45
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:13
float hash01(uint32_t a, uint32_t b)
Computes a pseudo-random float in [0, 1) by hashing two 32-bit integers.
Definition hash.cpp:22
float uniform01(uint64_t h)
Converts a 64-bit hash value into a deterministic uniform float in [0, 1).
Definition hash.cpp:62
float vnoise(float x, float y, uint32_t seed=0)
Computes 2D value noise in [-1, 1] using a hash-based lattice.
Definition hash.cpp:67