From 16bf2b181158dfb1a70d5f892ce1b09c63ce438c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bor=20Gro=C5=A1elj=20Simi=C4=87?= Date: Thu, 10 Feb 2022 01:47:56 +0100 Subject: [PATCH] rng: avoid recomputing a constant every time --- util.ha | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util.ha b/util.ha index 54d1d38..3b96595 100644 --- a/util.ha +++ b/util.ha @@ -1,13 +1,13 @@ -use math; use math::random; -use types; let rng: math::random::random = 0u64; +// math::nextafterf64(types::U64_MAX: f64, types::U64_MAX: f64 * 2); +const u64_max: f64 = 1.8446744073709556e+19; + export fn random(min: f64, max: f64) f64 = { let n = math::random::next(&rng); - return min + (max - min) * - math::nextafterf64(n: f64 / types::I64_MAX: f64, 0.0); + return min + (max - min) * (n: f64 / u64_max); }; export fn clamp(x: f64, min: f64, max: f64) f64 = -- 2.45.2