From: Jérôme Benoit Date: Sun, 20 Jun 2021 12:49:22 +0000 (+0200) Subject: Optimize random fluctuated computation X-Git-Tag: v1.0.23~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=97ef739c0f207e2b729bd3f185c463eb0ff35c7d;p=e-mobility-charging-stations-simulator.git Optimize random fluctuated computation Signed-off-by: Jérôme Benoit --- 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 {