Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package jason.functions;
 

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(s):
Jomi
See also:
floor
ceil
public class Random extends DefaultArithFunction  {
    public String getName() {
        return "math.random";
    }
    
    @Override
    public double evaluate(TransitionSystem tsTerm[] argsthrows Exception {
        if (args.length == 1 && args[0].isNumeric()) {
            return Math.random() * ((NumberTerm)args[0]).solve();
        } else {
            return Math.random();
        }
    }
    @Override
    public boolean checkArity(int a) {
        return a == 0 || a == 1;
    }
    
New to GrepCode? Check out our FAQ X