Orrery
A GPU-accelerated N-body gravitational simulator
Loading...
Searching...
No Matches
orrery::core::RandomSource Class Reference

A seeded stream of random numbers. More...

#include <orrery/core/random.hpp>

Public Member Functions

 RandomSource (std::uint64_t seed) noexcept
 Start a stream from the given seed.
std::uint64_t seed () const noexcept
 The seed this stream was started from.
Real uniform () noexcept
 A number in [0, 1).
Real uniform (Real low, Real high) noexcept
 A number in [low, high).
Vec3 unit_vector () noexcept
 A direction drawn uniformly over the unit sphere.

Detailed Description

A seeded stream of random numbers.

Passed by reference to everything that needs randomness, so that one run draws from one stream. Two generators seeded independently inside one setup would make the configuration depend on the order in which they happened to be constructed.

Constructor & Destructor Documentation

◆ RandomSource()

orrery::core::RandomSource::RandomSource ( std::uint64_t seed)
explicitnoexcept

Start a stream from the given seed.

There is no default seed and no seeding from a device. A generator that can be constructed without a seed will eventually be constructed without one, and the run that produced a result will not be repeatable.

Member Function Documentation

◆ seed()

std::uint64_t orrery::core::RandomSource::seed ( ) const
inlinenodiscardnoexcept

The seed this stream was started from.

Kept so that whatever reports a result, a failing test or a run's metadata, can record the one number needed to reproduce it without the caller having to carry it alongside.

◆ uniform()

Real orrery::core::RandomSource::uniform ( )
nodiscardnoexcept

A number in [0, 1).

Half open at the top on purpose: several samplers below divide by the value or raise it to a negative power, and the closed form would make those unbounded once in every few billion draws.

◆ unit_vector()

Vec3 orrery::core::RandomSource::unit_vector ( )
nodiscardnoexcept

A direction drawn uniformly over the unit sphere.

Every spherically symmetric configuration in the project needs one, and the obvious construction, an angle from each of two uniform draws, is wrong: it concentrates points at the poles. Uniformity in area needs the cosine of the polar angle to be the uniform variable, which is what this does.


The documentation for this class was generated from the following file: