/******************************************************************************* | |
* Copyright (c) 2004-2008 Andras Schmidt, Andras Balogh, Istvan Rath and Daniel Varro | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* | |
* Contributors: | |
* Gabor Bergmann, Istvan Rath - initial API and implementation | |
*******************************************************************************/ | |
package org.eclipse.viatra2.natives; | |
import java.util.Random; | |
import org.eclipse.viatra2.core.IModelSpace; | |
import org.eclipse.viatra2.errors.VPMRuntimeException; | |
import org.eclipse.viatra2.natives.NativeFunctionParameter.ParameterType; | |
/** | |
* Native function to generate a fresh random number. | |
* | |
* @author Gabor Bergmann | |
* | |
*/ | |
@VIATRANativeFunction(name = "randomDouble", remark = "Returns a fresh random number between 0.0 and 1.0.", params = {}, returns = { ParameterType.DOUBLE }) | |
public class RandomDoubleFunction implements ASMNativeFunction { | |
Random random = new Random(); | |
public Object evaluate(IModelSpace msp, Object[] params) | |
throws VPMRuntimeException { | |
return random.nextDouble(); | |
} | |
public String getDescription() { | |
return "Returns a fresh random number between 0.0 and 1.0."; | |
} | |
public String getID() { | |
return this.getClass().getCanonicalName(); | |
} | |
public String getName() { | |
return "randomDouble"; // ez megy a VTCLbe | |
} | |
} |