From 97ef739c0f207e2b729bd3f185c463eb0ff35c7d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 20 Jun 2021 14:49:22 +0200 Subject: [PATCH] Optimize random fluctuated computation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/utils/Utils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 5184bce7..38a212ca 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -129,7 +129,8 @@ export default class Utils { if (fluctuationPercent === 0) { return Utils.roundTo(staticValue, scale); } - return Utils.getRandomFloatRounded(staticValue + staticValue * (fluctuationPercent / 100), staticValue - staticValue * (fluctuationPercent / 100), scale); + const fluctuationRatio = fluctuationPercent / 100; + return Utils.getRandomFloatRounded(staticValue * (1 + fluctuationRatio), staticValue * (1 - fluctuationRatio), scale); } static cloneObject(object: T): T { -- 2.34.1