shuffle

Table of Contents

Prototype: shuffle(list, seed)

Return type: slist

Description: Return list shuffled with seed.

This function can accept many types of data parameters.

The same seed will produce the same shuffle every time. For a random shuffle, provide a random seed with the randomint function.

Arguments:

  • list: string, in the range: .*
  • seed: string, in the range: .*

Example:

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

bundle agent test
{
  vars:
      "mylist" slist => { "b", "c", "a" };
      "seeds" slist => { "xx", "yy", "zz" };

      "shuffled_$(seeds)" slist => shuffle(mylist, $(seeds));

      "joined_$(seeds)" string => join(",", "shuffled_$(seeds)");

  reports:
      "shuffled RANDOMLY by $(seeds) = '$(joined_$(seeds))'";
}

Output:

R: shuffled RANDOMLY by xx = 'b,a,c'
R: shuffled RANDOMLY by yy = 'a,c,b'
R: shuffled RANDOMLY by zz = 'c,b,a'

History: The collecting function behavior was added in 3.9.

See also: sort(), about collecting functions, and data documentation.