Refactor random generators and add MT19937 with NumPy-compatible jump #3413
If we use 2.0f, then the range is 2-4 and we can subtract 3 to get -1..1, in 2 fewer instructions.
Also, this adapter is scalar-only - seems vectorizing would make sense.
Seems undesirable to hardcode the type. We can support any vector type, and use DFromV<V> d; then RebindToUnsigned<decltype(d)> to get the tag to pass to FromBits.
Makes the class noncopyable, not sure this const is worthwhile.
Could use CopyBytes instead of a loop.
Seems unnecessary, we're not using wraparound, right?
Thanks, I agree it makes sense to split AES and Xorshiro.
This is a large change, better to discuss the design of such things first.
As-is, this breaks a lot of (internal) dependencies, which is a non-starter. We could keep the existing header and build target, it can include the new headers, plus aliases.
It seems dubious to add Generator to core Highway - that should reside in contrib/, and I'm not seeing a lot of value added. How about we remove it?
Also, MT19937 is scalar and seems like a poor fit for Highway. It also has a large working set and is not a generator I'd encourage using. How about you keep the MT19937 (if you really can't/don't want to replace it with AES) in your project's source?
distributions/ currently seems unnecessary - or do we intend to extend it? If not, probably better to stay in the same directly.
BufferedBitGenerator: should we have lazy init in case it's unused?
jan-wassenberg
KimYannn
Random generation currently combines RNG backends, buffering, and distributions in
random-inl.h. This separates the reusablehwy::Generatorand uniform distributions from the Xoshiro and AES-CTR backends, so additional engines can use the same sampling and fill interfaces.hwy/generator.hand providehwy/generator-inl.hfor native SIMD returns with per-target attributes. Move distributions tohwy/contrib/distributionsand engines/buffering to dedicated random headers.random-inl.hwrapper API and Bazel:randomtarget; migrate existing callers and update CMake, Bazel, and Meson registration. This is an include/API breaking change.std::mt19937single-integer seeding, shared u32/u64 consumption, andJump/Jumpedmatching native NumPy 2.5.3 state and cursor behavior for the same starting state. Keep state refill out of the hot draw path to allow inlining into bulk generation.Validation:
-O0and-O2. The previous version reproduces the CI's 16 vector-return target errors under the same options. SVE runtime testing is left to CI..jumped(): 889 scenarios and 38,542,776 matching outputs, covering cursor boundaries, repeated jumps, mixed u32/u64 consumption, and independent copies. Initial states were aligned usingRandomState(seed); this does not claim NumPySeedSequenceinitialization compatibility.