Difference between revisions of "LlListRandomize"

From Second Life Wiki
Jump to navigation Jump to search
m (your edits are getting better.)
Line 20: Line 20:
|caveats=
|caveats=
|examples=
|examples=
<lsl>
<lsl>list dice = ["2", "4", "1", "6", "3", "5"];
list dice = ["2", "4", "1", "6", "3", "5"];


default
default
Line 29: Line 28:
         llOwnerSay(llList2CSV(shuffled));
         llOwnerSay(llList2CSV(shuffled));
     }
     }
}
}</lsl>
</lsl>




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


list list_random = llListRandomize(list01, 2);</lsl>


list list01 = ["Cold", "pizza", "in", "the", "early", "morning"];
<tt>list_random</tt> could be:


 
# ["Cold", "pizza", "in", "the", "early", "morning"]
<lsl>
# ["Cold", "pizza", "early", "morning", "in", "the"]
list list_random = llListRandomize(list01, 2);
# ["in", "the", "Cold", "pizza", "early", "morning"]
</lsl>
# ["in", "the", "early", "morning", "Cold", "pizza"]
 
# ["early", "morning", "Cold", "pizza", "in", "the"]
This could return:
# ["early", "morning", "in", "the", "Cold", "pizza"]
 
1) "Cold", "pizza", "in", "the", "early", "morning"<br />
2) "Cold", "pizza", "early", "morning", "in", "the"<br />
3) "in", "the", "Cold", "pizza", "early", "morning"<br />
4) "in", "the", "early", "morning", "Cold", "pizza"<br />
5) "early", "morning", "Cold", "pizza", "in", "the"<br />
6) "early", "morning", "in", "the", "Cold", "pizza"<br />


Notice that two adjacent elements from the original list are always kept together, because the stride of 2 was specified.
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);</lsl>


 
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.
<lsl>
list list_random = llListRandomize(list01, 6);
</lsl>
 
Returns 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.
|constants
|constants
|helpers
|helpers

Revision as of 04:00, 14 July 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

This function supports Strided Lists.

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, src.length() % stride must be 0.

Conceptually, the algorithm selects src.length()/stride buckets, and then for each bucket swaps in 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>


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

list list_random = llListRandomize(list01, 2);</lsl>

list_random could be:

  1. ["Cold", "pizza", "in", "the", "early", "morning"]
  2. ["Cold", "pizza", "early", "morning", "in", "the"]
  3. ["in", "the", "Cold", "pizza", "early", "morning"]
  4. ["in", "the", "early", "morning", "Cold", "pizza"]
  5. ["early", "morning", "Cold", "pizza", "in", "the"]
  6. ["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);</lsl>

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.

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 );