Generator strategies

In order to generate numbers, a generator needs one strategy. This encapsulates the algorithm used to get values. There are several of them to choose from in NumGen, but developers can always implement new ones according to their needs.

FunctionStrategy

Based on the superb expression parser MESP, FunctionStrategy can generate numbers after a function, which makes it most powerful. In fact, other strategies could be considered obsolete and replaceable by FunctionStrategy; for example, ConstantStrategy could be replaced by a function like f(x) = K, or RandomStrategy by f(x) = rand(). However, these are maintained for performance reasons (they don't need to call a parser to interpret a function).
Functions in NumGen can use:

  • the variable x, whose value is the iteration number (i.e. 0 for the first generated value, 1 for the second one and so on).
  • the predefined functions which come with MESP (see their javadocs for a complete list).
  • user-defined functions: in fact, number generators with a name. Suppose you have two generators named gen1 and gen2. Then a new generator - say gen3 - could use a function like gen2(x)/(5*gen1(x+1)).
    Note that user-defined functions:
    • have only one parameter, which is the index of the value requested to the corresponding generator.
    • can be generators using any strategy.
    • check their dependency on other generators, in order to avoid deadlocks.