Random_MSWS.hpp

A versatile and non-patterned pseudo-random-number generator. Status: RELEASE.

This file is part of Empirical, https://github.com/devosoft/Empirical Copyright (C) 2025 Michigan State University MIT Software license; see doc/LICENSE.md

Defines

INCLUDE_EMP_MATH_RANDOM_MSWS_HPP_GUARD
struct Random_MSWS
#include <Random_MSWS.hpp>

Middle Square Weyl Sequence: A solid 32-bit pseudo-random-number engine generator. https://arxiv.org/abs/1704.00358 Based on: https://en.wikipedia.org/wiki/Middle-square_method

Public Functions

inline std::string GetType() const noexcept
inline uint32_t Get() noexcept

Return a 32-bit Random number.

inline uint64_t Get64() noexcept

Return a 64-bit Random number.

inline void ResetSeed(const uint64_t seed) noexcept

Starts a new sequence of pseudo random numbers. Seed is guaranteed > 0.

Public Members

uint64_t value = 0

Current squaring value.

uint64_t weyl_state = 0

Weyl sequence state.

uint64_t value2 = 0

Extra squaring value for 64 bit.

uint64_t weyl_state2 = 0

Extra Weyl sequence state for 64 bit.

Public Static Attributes

static constexpr uint64_t STEP_SIZE = 0xb5ad'4ece'da1c'e2a9
static constexpr uint64_t STEP_SIZE2 = 0x278c'5a4d'8419'fe6b