1516X Push Back 1.0
1516X's robot code for the 2025-2026 VEX Robotics Competition
Loading...
Searching...
No Matches
MCL::XorShift32 Struct Reference

Public Member Functions

 XorShift32 (uint32_t seed=pros::micros())
uint32_t next_u32 ()
float next_f32 ()
float uniform (float lo, float hi)
float gaussian (float std_dev)

Public Attributes

uint32_t state

Detailed Description

Definition at line 54 of file MCL.cpp.

Constructor & Destructor Documentation

◆ XorShift32()

MCL::XorShift32::XorShift32 ( uint32_t seed = pros::micros())
inlineexplicit

Definition at line 56 of file MCL.cpp.

57 : state(seed == 0 ? 0x12345678u : seed) {}
uint32_t state
Definition MCL.cpp:55

References state.

Member Function Documentation

◆ gaussian()

float MCL::XorShift32::gaussian ( float std_dev)
inline

Definition at line 65 of file MCL.cpp.

65 {
66 const float u1 = std::max(next_f32(), 1e-12f);
67 const float u2 = next_f32();
68 return std_dev * std::sqrt(-2.0f * std::log(u1))
69 * std::cos(2.0f * (float)M_PI * u2);
70 }
float next_f32()
Definition MCL.cpp:63

References next_f32().

◆ next_f32()

float MCL::XorShift32::next_f32 ( )
inline

Definition at line 63 of file MCL.cpp.

63{ return (next_u32() >> 8) * (1.0f / (1u << 24)); }
uint32_t next_u32()
Definition MCL.cpp:58

References next_u32().

Referenced by gaussian(), and uniform().

◆ next_u32()

uint32_t MCL::XorShift32::next_u32 ( )
inline

Definition at line 58 of file MCL.cpp.

58 {
59 uint32_t x = state;
60 x ^= x << 13; x ^= x >> 17; x ^= x << 5;
61 return state = x;
62 }

References state.

Referenced by next_f32().

◆ uniform()

float MCL::XorShift32::uniform ( float lo,
float hi )
inline

Definition at line 64 of file MCL.cpp.

64{ return lo + next_f32() * (hi - lo); }

References next_f32().

Member Data Documentation

◆ state

uint32_t MCL::XorShift32::state

Definition at line 55 of file MCL.cpp.

Referenced by XorShift32(), and next_u32().


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