Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Interpretml Interpret RandomDeterministic Hpp

From Leeroopedia


Knowledge Sources
Domains Machine_Learning, EBM_Core
Last Updated 2026-02-07 12:00 GMT

Overview

Declares the RandomDeterministic class implementing the Middle Square Weyl Sequence pseudo-random number generator with a mathematically proven 2^64 cycle.

Description

The RandomDeterministic.hpp header defines the RandomDeterministic class, a deterministic PRNG based on the Middle Square Weyl Sequence algorithm (arxiv:1704.00358). The core Rand32 method generates 32-bit random numbers using just 4 machine instructions: imulq, two iaddq, and rorq. The class maintains three uint64_t state variables (m_state1, m_state2, m_stateSeedConst) and provides Initialize methods for seeding from SeedEbm, uint64_t, or copying from another instance. The NextFast method generates uniformly distributed random numbers in a given range using rejection sampling to avoid modulo bias. The Next method provides a more careful implementation for ranges where the fast approximation might have too much bias. The RNG has a proven cycle of 2^64, which at 3GHz clock speed would take 195 years to exhaust.

Usage

Used throughout the boosting process for bagging (random sample selection), feature ordering randomization, and tie-breaking. Each thread gets its own seeded instance to ensure thread-safe deterministic behavior. The class is designed to be copied to the stack before hot loops for optimal register allocation.

Code Reference

Source Location

Signature

class RandomDeterministic final {
   uint64_t m_state1;
   uint64_t m_state2;
   uint64_t m_stateSeedConst;

   INLINE_ALWAYS uint_fast32_t Rand32();
   static uint_fast64_t GetOneTimePadConversion(uint_fast64_t seed);

public:
   void Initialize(const uint64_t seed);
   INLINE_ALWAYS void Initialize(const SeedEbm seed);
   INLINE_ALWAYS void Initialize(const RandomDeterministic& other);

   template<typename T> INLINE_ALWAYS T NextFast(const T maxPlusOne);
   template<typename T> INLINE_ALWAYS T Next(const T maxPlusOne);
};

I/O Contract

Method Input Output Description
Initialize seed value (state) Seeds the RNG internal state
Rand32 (state) uint_fast32_t Generates one 32-bit random value
NextFast maxPlusOne T in [0, maxPlusOne) Fast uniform random with small bias
Next maxPlusOne T in [0, maxPlusOne) Careful uniform random, no bias

Usage Examples

# Called internally via native bindings
from interpret.glassbox import ExplainableBoostingClassifier
ebm = ExplainableBoostingClassifier(random_state=42)
ebm.fit(X, y)  # RandomDeterministic provides deterministic randomness for bagging

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment