Orrery
A GPU-accelerated N-body gravitational simulator
Toggle main menu visibility
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
38
namespace
orrery::core {
39
46
class
RandomSource
{
47
public
:
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
81
private:
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
orrery::core::RandomSource::uniform
Real uniform() noexcept
A number in [0, 1).
orrery::core::RandomSource::seed
std::uint64_t seed() const noexcept
The seed this stream was started from.
Definition
random.hpp:60
orrery::core::RandomSource::unit_vector
Vec3 unit_vector() noexcept
A direction drawn uniformly over the unit sphere.
orrery::core::RandomSource::RandomSource
RandomSource(std::uint64_t seed) noexcept
Start a stream from the given seed.
orrery::core::Vec3
A vector in three-dimensional Euclidean space.
Definition
vec3.hpp:26
types.hpp
The scalar and index types that every layer of the project agrees on.
vec3.hpp
A three-component vector for interfaces, not for storage.
orrery
core
random.hpp
Generated by
1.17.0