From 5b23e1898cf838f6c7eacb7514d78bab54233b4d Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Thu, 27 Feb 2020 22:27:50 +0100 Subject: [PATCH] Fix bias in integer randomization --- orx-gui/src/main/kotlin/Gui.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/orx-gui/src/main/kotlin/Gui.kt b/orx-gui/src/main/kotlin/Gui.kt index b8d79246..7cf8cdc6 100644 --- a/orx-gui/src/main/kotlin/Gui.kt +++ b/orx-gui/src/main/kotlin/Gui.kt @@ -18,6 +18,7 @@ import org.openrndr.panel.elements.* import org.openrndr.panel.style.* import java.io.File +import kotlin.math.roundToInt import kotlin.reflect.KMutableProperty1 /** Dear contributor, just in case you are here looking to add a new parameter type. @@ -506,7 +507,7 @@ class GUI : Extension { val max = parameter.intRange!!.last val currentValue = (parameter.property as KMutableProperty1).get(labeledObject.obj) val randomValue = Math.random() * (max - min) + min - val newValue = ((1.0 - strength) * currentValue + randomValue * strength).toInt() + val newValue = ((1.0 - strength) * currentValue + randomValue * strength).roundToInt() (parameter.property as KMutableProperty1).set(labeledObject.obj, newValue) } ParameterType.Boolean -> {