Skip to content
lsl.devlsl.devLSL Dev

llListRandomize

function
Function syntax
list llListRandomize(
  1. list src,// Source list to randomize.
  2. integer stride// Size of each randomized block (defaults to 1 if less than 1).
);
Returns
list
Energy
10

Returns a randomized copy of the list src by blocks of size stride. If the list length is not perfectly divisible by stride, no randomization occurs.

Returns a list which is a randomized permutation of src.

How to use
list result = llListRandomize([], 0);

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.

Example 1
list dice = ["2", "4", "1", "6", "3", "5"];
default
{
touch_start(integer num_detected) {
list shuffled = llListRandomize(dice, 1);
llOwnerSay(llList2CSV(shuffled));
}
}
Example 2
list list01 = ["Cold", "pizza", "in", "the", "early", "morning"];
list list_random = llListRandomize(list01, 2);
list_random could be:
  • [“Cold”, “pizza”, “in”, “the”, “early”, “morning”]
  • [“Cold”, “pizza”, “early”, “morning”, “in”, “the”]
  • [“in”, “the”, “Cold”, “pizza”, “early”, “morning”]
  • [“in”, “the”, “early”, “morning”, “Cold”, “pizza”]
  • [“early”, “morning”, “Cold”, “pizza”, “in”, “the”]
  • [“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.)

Original wiki source

Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.