Volatile functions
I’m writing a plugin function which is volatile – repeated calls to it return varying values – but I’m having trouble making this work.
As an example, consider the built-in rand() function. This returns a different value after each call (i.e. it has type “”IO double”” rather than “”double””, to borrow the Haskell convention).
Now if I write a Groovy function:
double groovy_rand() {
return new Random().nextDouble();
}
Then this behaves as I would expect, in that a 2D matrix with e.g. A1 = groovy_rand() produces a list of random numbers across category B.
But if I write a plugin function:
public class PluginRand extends AbstractQFunction {
public QValueList evaluate(QValueList[] args) {
return QValueFactory.createSingletonValueList(new Random().nextDouble());
}
public QType[] argumentTypes() {
return new QType[] {};
}
public QType returnType() {
return QType.cValueType;
}
}
then doing the same A1 = pluginrand() just produces a list across B of the same *first* random number.
How can I obtain the Groovy-like volatile behaviour from a plugin?
Many thanks.