Skip to content
Merged
Changes from 3 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
10 changes: 10 additions & 0 deletions stl/inc/random
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,16 @@ _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) {
// minstd_rand
constexpr unsigned long long _All = static_cast<unsigned long long>(_Ax);
constexpr unsigned long long _Mll = static_cast<unsigned long long>(_Mx);

auto _Mul = static_cast<unsigned long long>(_Prev) * _All;
_Mul = (_Mul >> 31) + (_Mul & _Mll);
_Mul = _Mul < _Mll ? _Mul : _Mul - _Mll;

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