Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions stl/inc/random
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,13 @@ _NODISCARD _Uint _Next_linear_congruential_value(_Uint _Prev) noexcept {
// numeric_limits<result_type>::max() plus 1." That is: Just do the multiply
// and let normal unsigned modulo take care of it
return static_cast<_Uint>(static_cast<_Uint>(_Ax * _Prev) + _Cx);
} else if constexpr (_Cx == 0 && _Mx == 2147483647) {
// for minstd_rand and minstd_rand0 we can improve performance by avoiding constant divisions
auto _Mul = static_cast<unsigned long long>(_Prev) * _Ax;
_Mul = (_Mul >> 31) + (_Mul & _Mx);
_Mul = _Mul < _Mx ? _Mul : _Mul - _Mx;

return static_cast<_Uint>(_Mul);
} else if constexpr (_Cx <= UINT_MAX && static_cast<_Uint>(_Mx - 1) <= (UINT_MAX - _Cx) / _Ax) {
// unsigned int is sufficient to store intermediate calculation
const auto _Mul =
Expand Down