randomint

Table of Contents

Prototype: randomint(lower, upper)

Return type: int

Description: Returns a random integer between lower and up to but not including upper.

The limits must be integer values and the resulting numbers are based on the entropy of the md5 algorithm.

The upper limit is excluded from the range. Thus randomint(0, 100) will return 100 possible values, not 101.

The function will be re-evaluated on each pass if it is not restricted with a context class expression as shown in the example.

Arguments:

  • lower: int, in the range: -99999999999,99999999999
  • upper: int, in the range: -99999999999,99999999999

Example:

body common control
{
      bundlesequence => { "randomint_example" };
}

bundle agent randomint_example
{
  vars:
      "low"    string => "4";
      "high"   string => "60";

      "random"    int => randomint($(low), $(high));
  classes:
      "isabove" expression => isgreaterthan($(random), 3);

  reports:
    isabove::
      "The generated random number was above 3";
}

Output:

R: The generated random number was above 3