# llListRandomize

*LSL function*

```lsl
list list llListRandomize(list src, integer stride);
```

- `list src`: Source list to randomize.
- `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](https://wiki.secondlife.com/wiki/list) which is a randomized permutation of **src**.

```lsl title="How to use" frame="terminal"
list result = llListRandomize([], 0);
```

## 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

<details open>
<summary>Example 1</summary>

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

default
{
    touch_start(integer num_detected) {
        list shuffled = llListRandomize(dice, 1);
        llOwnerSay(llList2CSV(shuffled));
    }
}
```

</details>

<details>
<summary>Example 2</summary>

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

list list_random = llListRandomize(list01, 2);
```

</details>

<details>
<summary>`list_random` could be:</summary>

- \["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.

```lsl
list list_random = llListRandomize(list01, 6);
```

</details>

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

- [llListSort](/functions/llListSort/)
- [llFrand](/functions/llFrand/)

---

*Source: [LlListRandomize](https://wiki.secondlife.com/wiki/LlListRandomize) on the Second Life Wiki. Content from the Second Life Wiki articles LlListRandomize (revision 1194342, 2015-01-22) and Template:LSL Function/stride (revision 1190281, 2014-05-03), CC BY-SA 3.0.*

---

From lsl.dev: https://lsl.dev/functions/llListRandomize/
