Orrery
A GPU-accelerated N-body gravitational simulator
Loading...
Searching...
No Matches
random.hpp
Go to the documentation of this file.
1#pragma once
2
30
31#include <cstdint>
32#include <limits>
33#include <random>
34
35#include "orrery/core/types.hpp"
36#include "orrery/core/vec3.hpp"
37
38namespace orrery::core {
39
47public:
53 explicit RandomSource(std::uint64_t seed) noexcept;
54
60 [[nodiscard]] std::uint64_t seed() const noexcept { return seed_; }
61
67 [[nodiscard]] Real uniform() noexcept;
68
70 [[nodiscard]] Real uniform(Real low, Real high) noexcept;
71
79 [[nodiscard]] Vec3 unit_vector() noexcept;
80
81private:
91 static constexpr int kMantissaBits = std::numeric_limits<Real>::digits;
92
96 static constexpr Real kScale = Real{1} / static_cast<Real>(std::uint64_t{1} << kMantissaBits);
97
98 std::uint64_t seed_;
99 std::mt19937_64 engine_;
100};
101
102} // namespace orrery::core
Real uniform() noexcept
A number in [0, 1).
std::uint64_t seed() const noexcept
The seed this stream was started from.
Definition random.hpp:60
Vec3 unit_vector() noexcept
A direction drawn uniformly over the unit sphere.
RandomSource(std::uint64_t seed) noexcept
Start a stream from the given seed.
A vector in three-dimensional Euclidean space.
Definition vec3.hpp:26
The scalar and index types that every layer of the project agrees on.
A three-component vector for interfaces, not for storage.