Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::signal::Xorshift32 Class Reference

Xorshift32 (Marsaglia, "Xorshift RNGs", J. More...

#include <rng.hpp>

Public Member Functions

constexpr Xorshift32 ()=default
constexpr Xorshift32 (std::uint32_t s)
void seed (std::uint32_t s)
void set_seed (std::uint32_t s)
 Compatibility spelling used by the Round 2 DSP blocks.
void reset ()
 Rewind to the seeded stream position.
std::uint32_t next_u32 ()
std::uint32_t next_uint ()
 Compatibility spelling used by the Round 2 DSP blocks.
float next_unipolar ()
 Uniform in [0, 1).
float next_bipolar ()
 Uniform in [-1, 1).
template<typename T>
T next_bipolar ()
float next_unit ()
 Uniform in [0, 1), with the caller-selected result precision.
template<typename T>
T next_unit ()
float gaussian ()
 Standard normal via the polar-free Box-Muller transform (Box & Muller, Ann.
std::uint32_t state () const
std::uint32_t seed () const

Static Public Attributes

static constexpr std::uint32_t kDefaultSeed = 0x9E3779B9u
 Any nonzero constant works; this is the 32-bit golden-ratio odd constant, which is also what seed(0) normalizes to.

Detailed Description

Xorshift32 (Marsaglia, "Xorshift RNGs", J.

Stat. Soft. 8(14), 2003) with the canonical 13/17/5 triple.

Zero is the generator's fixed point — a zero-initialized instance would emit zeros forever — so the state is defaulted to a nonzero constant and a zero state is repaired lazily on use. That keeps "zero-init = fresh" true for aggregates that embed this without a constructor call.

Constructor & Destructor Documentation

◆ Xorshift32() [1/2]

pulp::signal::Xorshift32::Xorshift32 ( )
constexprdefault

◆ Xorshift32() [2/2]

pulp::signal::Xorshift32::Xorshift32 ( std::uint32_t s)
inlineexplicitconstexpr

Member Function Documentation

◆ gaussian()

float pulp::signal::Xorshift32::gaussian ( )
inline

Standard normal via the polar-free Box-Muller transform (Box & Muller, Ann.

Math. Statist. 29(2), 1958). The transform produces two independent deviates per pair of uniforms; the second is cached so the amortized cost is one log/sqrt/sincos pair every other call.

u1 is drawn on (0, 1] rather than [0, 1) — log(0) is the one input that breaks the transform.

◆ next_bipolar() [1/2]

template<typename T>
T pulp::signal::Xorshift32::next_bipolar ( )
inline

◆ next_bipolar() [2/2]

float pulp::signal::Xorshift32::next_bipolar ( )
inline

Uniform in [-1, 1).

◆ next_u32()

std::uint32_t pulp::signal::Xorshift32::next_u32 ( )
inline

◆ next_uint()

std::uint32_t pulp::signal::Xorshift32::next_uint ( )
inline

Compatibility spelling used by the Round 2 DSP blocks.

◆ next_unipolar()

float pulp::signal::Xorshift32::next_unipolar ( )
inline

Uniform in [0, 1).

Built from the top 24 bits so every result is exactly representable in float and the spacing is uniform.

◆ next_unit() [1/2]

template<typename T>
T pulp::signal::Xorshift32::next_unit ( )
inline

◆ next_unit() [2/2]

float pulp::signal::Xorshift32::next_unit ( )
inline

Uniform in [0, 1), with the caller-selected result precision.

◆ reset()

void pulp::signal::Xorshift32::reset ( )
inline

Rewind to the seeded stream position.

reset() restores the seed the caller set, not the default one — a reset that silently discarded the seed would make every seeded object share one stream, which is the opposite of what seeding is for.

◆ seed() [1/2]

std::uint32_t pulp::signal::Xorshift32::seed ( ) const
inline

◆ seed() [2/2]

void pulp::signal::Xorshift32::seed ( std::uint32_t s)
inline

◆ set_seed()

void pulp::signal::Xorshift32::set_seed ( std::uint32_t s)
inline

Compatibility spelling used by the Round 2 DSP blocks.

◆ state()

std::uint32_t pulp::signal::Xorshift32::state ( ) const
inline

Member Data Documentation

◆ kDefaultSeed

std::uint32_t pulp::signal::Xorshift32::kDefaultSeed = 0x9E3779B9u
staticconstexpr

Any nonzero constant works; this is the 32-bit golden-ratio odd constant, which is also what seed(0) normalizes to.


The documentation for this class was generated from the following file:
  • /home/runner/work/pulp/pulp/core/signal/include/pulp/signal/rng.hpp