Date: Fri, 5 Dec 2025 22:32:37 +0000
On 04/12/2025 19:05, Juan Lucas Rey via Std-Proposals wrote:
> in the current proposal,
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p0952r2.html
>
> it is mentioned "In particular, code that depends on a specific
> sequence of results from repeated invocations, or on a particular
> number of calls to the URBG argument, will be broken."
>
> This solution avoids breaking this.
In the attached proposal within the implementation of exponential_distribution you have:
const auto u
= std::generate_canonical_centered<
result_type,
std::numeric_limits<result_type>::digits
>(g);
if (std::copysign(1.0, u) > 0) {
return -std::log(result_type(1) - u) * lambda_inv;
} else {
return -std::log(-u) * lambda_inv;
}
This is exactly equivalent to:
const auto u = ...
const auto u2
= std::copysign(1.0, u) > 0
? result_type(1) - u
: -u;
return -std::log(u2) * lambda_inv;
Generating the centered uniform distribution seems redundant, you effectively map it to a
uniform distribution on [0, 1) anyway with u2. So this also boils down to fixing the
distribution on [0, 1), and centering doesn't give you anything for this particular use
case. You throw away your increased resolution at `result_type(1) - u`.
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
> in the current proposal,
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p0952r2.html
>
> it is mentioned "In particular, code that depends on a specific
> sequence of results from repeated invocations, or on a particular
> number of calls to the URBG argument, will be broken."
>
> This solution avoids breaking this.
In the attached proposal within the implementation of exponential_distribution you have:
const auto u
= std::generate_canonical_centered<
result_type,
std::numeric_limits<result_type>::digits
>(g);
if (std::copysign(1.0, u) > 0) {
return -std::log(result_type(1) - u) * lambda_inv;
} else {
return -std::log(-u) * lambda_inv;
}
This is exactly equivalent to:
const auto u = ...
const auto u2
= std::copysign(1.0, u) > 0
? result_type(1) - u
: -u;
return -std::log(u2) * lambda_inv;
Generating the centered uniform distribution seems redundant, you effectively map it to a
uniform distribution on [0, 1) anyway with u2. So this also boils down to fixing the
distribution on [0, 1), and centering doesn't give you anything for this particular use
case. You throw away your increased resolution at `result_type(1) - u`.
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2025-12-05 22:32:43
