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 51 of file MCL.cpp.

Constructor & Destructor Documentation

◆ XorShift32()

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

Definition at line 53 of file MCL.cpp.

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

References state.

Member Function Documentation

◆ gaussian()

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

Definition at line 62 of file MCL.cpp.

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

References next_f32().

◆ next_f32()

float MCL::XorShift32::next_f32 ( )
inline

Definition at line 60 of file MCL.cpp.

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

References next_u32().

Referenced by gaussian(), and uniform().

◆ next_u32()

uint32_t MCL::XorShift32::next_u32 ( )
inline

Definition at line 55 of file MCL.cpp.

55 {
56 uint32_t x = state;
57 x ^= x << 13; x ^= x >> 17; x ^= x << 5;
58 return state = x;
59 }

References state.

Referenced by next_f32().

◆ uniform()

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

Definition at line 61 of file MCL.cpp.

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

References next_f32().

Member Data Documentation

◆ state

uint32_t MCL::XorShift32::state

Definition at line 52 of file MCL.cpp.

Referenced by XorShift32(), and next_u32().


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