All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jason.functions.Random Maven / Gradle / Ivy

The newest version!
package jason.functions;

import jason.asSemantics.DefaultArithFunction;
import jason.asSemantics.TransitionSystem;
import jason.asSyntax.NumberTerm;
import jason.asSyntax.Term;
import jason.stdlib.set_random_seed;

/**
   

Function: math.random(N): encapsulates java Math.random; If N is not informed: returns a value greater than or equal to 0.0 and less than 1.0; If N is informed: returns a value greater than or equal to 0.0 and less than N.

Examples:

  • math.random: returns the random number between 0 and 1.
  • math.random(10): returns the random number between 0 and 9.9999.
@author Jomi @see jason.functions.floor @see jason.functions.ceil */ public class Random extends DefaultArithFunction { public String getName() { return "math.random"; } @Override public double evaluate(TransitionSystem ts, Term[] args) throws Exception { java.util.Random r = set_random_seed.getAgRandomIA(ts); if (args.length == 1 && args[0].isNumeric()) { return r.nextDouble() * ((NumberTerm)args[0]).solve(); } else { return r.nextDouble(); } } @Override public boolean checkArity(int a) { return a == 0 || a == 1; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy