diff options
Diffstat (limited to 'absl/random')
-rw-r--r-- | absl/random/internal/nonsecure_base_test.cc | 7 | ||||
-rw-r--r-- | absl/random/log_uniform_int_distribution.h | 16 |
2 files changed, 13 insertions, 10 deletions
diff --git a/absl/random/internal/nonsecure_base_test.cc b/absl/random/internal/nonsecure_base_test.cc index d9de99019ce0..698027fc6e0d 100644 --- a/absl/random/internal/nonsecure_base_test.cc +++ b/absl/random/internal/nonsecure_base_test.cc @@ -154,9 +154,10 @@ TEST(NonsecureURBGBase, CompatibleWithDistributionUtils) { TEST(NonsecureURBGBase, CompatibleWithStdDistributions) { ExampleNonsecureURBG rbg; - std::uniform_int_distribution<uint32_t>(0, 100)(rbg); - std::uniform_real_distribution<float>()(rbg); - std::bernoulli_distribution(0.2)(rbg); + // Cast to void to suppress [[nodiscard]] warnings + static_cast<void>(std::uniform_int_distribution<uint32_t>(0, 100)(rbg)); + static_cast<void>(std::uniform_real_distribution<float>()(rbg)); + static_cast<void>(std::bernoulli_distribution(0.2)(rbg)); } TEST(NonsecureURBGBase, ConsecutiveDefaultInstancesYieldUniqueVariates) { diff --git a/absl/random/log_uniform_int_distribution.h b/absl/random/log_uniform_int_distribution.h index 956a69070ccd..de58bdbe14ca 100644 --- a/absl/random/log_uniform_int_distribution.h +++ b/absl/random/log_uniform_int_distribution.h @@ -192,13 +192,15 @@ log_uniform_int_distribution<IntType>::Generate( const double r = std::pow(p.base(), d); const double s = (r * p.base()) - 1.0; - base_e = (r > (std::numeric_limits<unsigned_type>::max)()) - ? (std::numeric_limits<unsigned_type>::max)() - : static_cast<unsigned_type>(r); - - top_e = (s > (std::numeric_limits<unsigned_type>::max)()) - ? (std::numeric_limits<unsigned_type>::max)() - : static_cast<unsigned_type>(s); + base_e = + (r > static_cast<double>((std::numeric_limits<unsigned_type>::max)())) + ? (std::numeric_limits<unsigned_type>::max)() + : static_cast<unsigned_type>(r); + + top_e = + (s > static_cast<double>((std::numeric_limits<unsigned_type>::max)())) + ? (std::numeric_limits<unsigned_type>::max)() + : static_cast<unsigned_type>(s); } const unsigned_type lo = (base_e >= p.range()) ? p.range() : base_e; |