mirror-llvm-project/libcxx/include/__random
Kyungtak Woo 66d049cdad
[libc++] Fix std::mt19937 seeding with std::seed_seq under vectorized ABI (#209860)
This PR fixes a bug in `std::mersenne_twister_engine::seed(_Sseq&)`
where the initialization twist is bypassed when the vectorized engine
optimization (`_LIBCPP_ABI_VECTORIZED_MERSENNE_TWISTER_ENGINE`) is
enabled.

In the vectorized implementation introduced in #206423, the engine state
must be pre-twisted during initialization by calling
`__update_all_states()` at the end of the `seed` functions.

However, in `seed(_Sseq& __q)`, the all-zero state check contains an
early `return;` when a non-zero state is verified. This early return
bypasses the trailing `__update_all_states()` call. Consequently, the
generator is initialized with raw, untwisted seed values (tempered)
rather than the standard twisted values.

This only manifests when compiled with unstable ABI settings
(`_LIBCPP_ABI_VERSION >= 2`) which enables the vectorized
implementation.

I replaced the early `return;` inside the all-zero state verification
block with a loop break, and conditionalized the zero-state fix using
the loop index `__i`, ensuring `__update_all_states()` is always
executed at the end of the function. Added regression tests to
`seed_sseq.pass.cpp` asserting the exact deterministic outputs for both
32-bit and 64-bit engines.
2026-07-30 09:08:22 -06:00
..
bernoulli_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
binomial_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
cauchy_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
chi_squared_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
clamp_to_integral.h
default_random_engine.h
discard_block_engine.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
discrete_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
exponential_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
extreme_value_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
fisher_f_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
gamma_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
generate_canonical.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
geometric_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
independent_bits_engine.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
is_seed_sequence.h [libc++] Make __is_seed_sequence a variable template (#195420) 2026-05-02 17:06:17 +02:00
is_valid.h
knuth_b.h
linear_congruential_engine.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
log2.h
lognormal_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
mersenne_twister_engine.h [libc++] Fix std::mt19937 seeding with std::seed_seq under vectorized ABI (#209860) 2026-07-30 09:08:22 -06:00
negative_binomial_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
normal_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
piecewise_constant_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
piecewise_linear_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
poisson_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
random_device.h [libc++] Consistently use version guards outside namespace macros (#181136) 2026-06-29 14:44:44 +02:00
ranlux.h
seed_seq.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
shuffle_order_engine.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
student_t_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
subtract_with_carry_engine.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
uniform_int_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
uniform_random_bit_generator.h [libc++] Consistently use version guards outside namespace macros (#181136) 2026-06-29 14:44:44 +02:00
uniform_real_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00
weibull_distribution.h [libc++][random] Applied [[nodiscard]] to <random> (#204970) 2026-06-22 20:40:07 +03:00