/* GeoGebra - Dynamic Mathematics for Everyone http://www.geogebra.org This file is part of GeoGebra. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. */ package org.geogebra.common.kernel.statistics; import org.geogebra.common.kernel.Construction; import org.geogebra.common.kernel.SetRandomValue; import org.geogebra.common.kernel.algos.AlgoTwoNumFunction; import org.geogebra.common.kernel.commands.Commands; import org.geogebra.common.kernel.geos.GeoNumberValue; /** * Computes RandomNormal[a, b] * * @author Michael Borcherds */ public class AlgoRandomUniform extends AlgoTwoNumFunction implements SetRandomValue { public AlgoRandomUniform(Construction cons, String label, GeoNumberValue a, GeoNumberValue b) { super(cons, label, a, b); // output is random number cons.addRandomGeo(num); } @Override public Commands getClassName() { return Commands.RandomUniform; } @Override public final void compute() { if (input[0].isDefined() && input[1].isDefined()) { num.setValue( a.getDouble() + kernel.getApplication().getRandomNumber() * (b.getDouble() - a.getDouble())); } else { num.setUndefined(); } } @Override public void setRandomValue(double d) { if (d >= a.getDouble() && d <= b.getDouble()) { num.setValue(d); num.updateRepaint(); } } }