From Second Life Wiki
Jump to navigation Jump to search


Function: list llListRandomize( list src, integer stride );

Returns a list which is a randomized permutation of src.

• list src A list you want to randomize.
• integer stride number of entries per stride, if less than 1 it is assumed to be 1

This function supports Strided Lists.


When you want to randomize the position of every list element, specify a stride of 1. This is perhaps the setting most used.

If the stride is not a factor of the list length, the src list is returned. In other words, llGetListLength(src) % stride must be 0.

Conceptually, the algorithm selects llGetListLength(src) / stride buckets, and then for each bucket swaps in the contents with another bucket.


list dice = ["2", "4", "1", "6", "3", "5"];

    touch_start(integer num_detected) {
        list shuffled = llListRandomize(dice, 1);

list list01 = ["Cold", "pizza", "in", "the", "early", "morning"];

list list_random = llListRandomize(list01, 2);

list_random could be:

  1. ["Cold", "pizza", "in", "the", "early", "morning"]
  2. ["Cold", "pizza", "early", "morning", "in", "the"]
  3. ["in", "the", "Cold", "pizza", "early", "morning"]
  4. ["in", "the", "early", "morning", "Cold", "pizza"]
  5. ["early", "morning", "Cold", "pizza", "in", "the"]
  6. ["early", "morning", "in", "the", "Cold", "pizza"]

Notice that two adjacent elements from the original list are always kept together, because the stride of 2 was specified.

list list_random = llListRandomize(list01, 6);
list_random in this instance is the original list, exactly in the order it already was, because we told it to keep every set of six elements together, and there are only six elements in the list.


Bear in mind that the source list will remain unchanged. Instead, a new list will be produced. So, it's important that you capture this with a variable (unless you are acting directly on the results.)

See Also


•  llListSort
•  llFrand

Deep Notes

Search JIRA for related Issues


lsa_randomize(): 'linden\indra\lscript\lscript_library\lscript_alloc.cpp'


function list llListRandomize( list src, integer stride );