llListRandomize
list llListRandomize(list ListVariable, integer Stride)Returns a version of the input ListVariable which has been randomized by blocks of size Stride.
If the remainder from the length of the list, divided by the stride is non-zero, this function does not randomize the list.
Parameters
-
ListVariable(list) -
Stride(integer)
Basic Randomization
Section titled “Basic Randomization”list dice = ["2", "4", "1", "6", "3", "5"];
default{ touch_start(integer num_detected) { list shuffled = llListRandomize(dice, 1); llOwnerSay(llList2CSV(shuffled)); }}Stride of 2
Section titled “Stride of 2”list list01 = ["Cold", "pizza", "in", "the", "early", "morning"];
list list_random = llListRandomize(list01, 2);With a stride of 2, list_random could be any of these permutations:
["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.
Stride Equals List Length
Section titled “Stride Equals List Length”list list_random = llListRandomize(list01, 6);In this case, list_random is the original list in its original order, because we told it to keep every set of six elements together, and there are only six elements in the list.
- The source list will remain unchanged. A new list is produced and returned. Capture this with a variable unless you are acting directly on the results.
- When you want to randomize the position of every list element, specify a stride of 1.
- If the stride is not a factor of the list length, the source list is returned unchanged. In other words,
llGetListLength(src) % stridemust equal 0. - Conceptually, the algorithm selects
llGetListLength(src) / stridebuckets, then swaps the contents of buckets with one another.