Skip to content
lsl.devlsl.devLSL Dev

LlListRandomize

Looking for the current API? Open the llListRandomize reference →

Return value notes

Returns a list which is a randomized permutation of src.

Specification

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.

Examples

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

default
{
    touch_start(integer num_detected) {
        list shuffled = llListRandomize(dice, 1);
        llOwnerSay(llList2CSV(shuffled));
    }
}
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.

Notes

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: functions

Shared wiki helpers

The original page also injects shared parameter notes, caveats or issue information through these helpers. Their conditional MediaWiki logic is not reproduced here; inspect the preserved helper source for additional material.

Template:LSL Function/stride

Original shared helper source (conditional wiki logic is not evaluated)
{{LSL Injection Test}}{{#if:

{{#vardefine:header_footnote|This function supports [[List#Strided_lists|Strided Lists]].}}

{{#vardefine:p_{{{1|none}}}_hover|number of entries per stride, if less than 1 it is assumed to be 1}}
{{#vardefine:p_{{{1|none}}}_desc|number of entries per stride, if less than 1 it is assumed to be 1}}

}}<noinclude>
{| {{Prettytable}}
|- {{Hl2}}
! #var
! value
|-
{{VarPair|p_{{{1|none}}}_desc}}
|-
{{VarPair|p_{{{1|none}}}_hover}}
|-
{{VarPair|header_footnote}}
|}
</noinclude>
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.