Difference between revisions of "LlListRandomize"

From Second Life Wiki
Jump to navigation Jump to search
(touch up example so that it compiles standalone)
m
Line 19: Line 19:
|examples=
|examples=
<lsl>
<lsl>
list dice = ["2", "4", "1", "6", "3", "5"];
default
default
{
{
     touch_start(integer num_detected) {
     touch_start(integer num_detected) {
        list dice = ["2", "4", "1", "6", "3", "5"];
         list shuffled = llListRandomize(dice, 1);
         list shuffled = llListRandomize(dice, 1);
         llOwnerSay(llList2CSV(shuffled));
         llOwnerSay(llList2CSV(shuffled));

Revision as of 19:14, 29 May 2008

Summary

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 How many list entries to keep next to each other during the randomization.

Specification

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 src list is returned. In other words, src.length() % stride must be 0.

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

Examples

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

default {

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

}

</lsl>

See Also

Functions

•  llListSort
•  llFrand

Deep Notes

Search JIRA for related Issues

Source

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

Signature

function list llListRandomize( list src, integer stride );