Package jason.stdlib
Class random
java.lang.Object
jason.asSemantics.DefaultInternalAction
jason.stdlib.random
- All Implemented Interfaces:
InternalAction
,java.io.Serializable
@Manual(literal=".random(value)", hint="generates a random number between 0 and 1", argsHint="the variable to receive the random value", argsType="number", examples={".random(X): unifies X with one random number between 0 and 1",".random(X, 5): unifies X with a random number between 0 and 1, and backtracks 5 times. For example: .findall(X, .random(X,5), L) will produce a list of 5 random numbers",".random(X, 0): unifies X with a random number between 0 and 1, and backtracks infinitely"}, seeAlso="jason.functions.Random") public class random extends DefaultInternalAction
Internal action: .random(N)
.
Description: unifies N with a random number between 0 and 1.
Parameter:
- + options> (list, optional): the list of possible values, default values are any real number
- - value (number): the variable that unifies with a random value from options
- + quantity of random values (number, optional): default value is 1, value = 0 means that an infinity number of random values will be produced (this is useful for some backtrack circumstances).
Example:
.random(X)
: unifies X with one random number between 0 and 1..random(X, 5)
: unifies X with a random number between 0 and 1, and backtracks 5 times. For example: .findall(X, .random(X,5), L) will produce a list of 5 random numbers..random(X, 0)
: unifies X with a random number between 0 and 1, and backtracks infinitely..random([a,b,c],X)
: unifies X with a random value from a, b, or c.
- See Also:
function version
, Serialized Form
-
Field Summary
Fields Modifier and Type Field Description private java.util.Random
random
-
Constructor Summary
Constructors Constructor Description random()
-
Method Summary
Modifier and Type Method Description protected void
checkArguments(Term[] args)
java.lang.Object
execute(TransitionSystem ts, Unifier un, Term[] args)
Executes the internal action.int
getMaxArgs()
int
getMinArgs()
java.util.Random
getRandomGenerator()
Methods inherited from class jason.asSemantics.DefaultInternalAction
canBeUsedInContext, destroy, prepareArguments, suspendIntention
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
random
private java.util.Random random
-
-
Constructor Details
-
random
public random()
-
-
Method Details
-
getRandomGenerator
public java.util.Random getRandomGenerator() -
getMinArgs
public int getMinArgs()- Overrides:
getMinArgs
in classDefaultInternalAction
-
getMaxArgs
public int getMaxArgs()- Overrides:
getMaxArgs
in classDefaultInternalAction
-
checkArguments
- Overrides:
checkArguments
in classDefaultInternalAction
- Throws:
JasonException
-
execute
public java.lang.Object execute(TransitionSystem ts, Unifier un, Term[] args) throws java.lang.ExceptionDescription copied from interface:InternalAction
Executes the internal action. It should return a Boolean or an Iterator. A true boolean return means that the IA was successfully executed. An Iterator result means that there is more than one answer for this IA (e.g. see member internal action). - Specified by:
execute
in interfaceInternalAction
- Overrides:
execute
in classDefaultInternalAction
- Throws:
java.lang.Exception
-