Difference between revisions of "LlListRandomize"

From Second Life Wiki
Jump to navigation Jump to search
(Undo revision 302833 by Nanjido Oh (Talk))
Line 1: Line 1:
{{LSL_Function/ko
{{LSL_Function
|sort=ListRandomize|func=llListRandomize
|sort=ListRandomize|func=llListRandomize
|func_id=197|func_sleep=0.0|func_energy=10.0
|func_id=197|func_sleep=0.0|func_energy=10.0
|p1_type=list
|p1_type=list
|p1_name=src
|p1_name=src
|p1_desc=무작위로 만들고자 하는 목록.
|p1_desc=A list you want to randomize.
|p2_type=integer
|p2_type=integer
|p2_name=stride
|p2_name=stride
|p2_desc=무작위를 하더라도 순서를 유지하고자 하는 인접한 절편의 길이.
|p2_desc=How many list entries to keep next to each other during the randomization.
|return_type=list
|return_type=list
|return_text=무작위로 섞인 '''src'''의 순열
|return_text=which is a randomized permutation of '''src'''.
|spec=
|spec=
이 함수는 [[List/ko#Strided_lists|절편 목록]]을 지원한다.
This function supports [[List#Strided_lists|Strided Lists]].


목록의 모든 항목 위치를 무작위로 섞고 싶다면 절편(stride) 길이를 1로 놓을 것. 대부분은 이런 식으로 사용된다.
When you want to randomize the position of every list element, specify a stride of 1. This is perhaps the setting most used.


절편 길이가 목록 길이의 약수가 아니라면, 목록 '''src'''가 그대로 반환된다. 다시 말해서, src.length() % stride 는 0이 되어야 한다.
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.


개념적으로, 알고리즘은 src.length()/stride한 절편들을 취해서, 각각의 절편을 다른 절편과 섞게 되는 것이다.
Conceptually, the algorithm selects src.length()/stride buckets, and then for each bucket swaps in the contents with another bucket.
|caveats=
|caveats=
|examples=
|examples=
Line 35: Line 35:
list list_random = llListRandomize(list01, 2);</lsl>
list list_random = llListRandomize(list01, 2);</lsl>


<tt>list_random</tt>은 이를테면 다음과 같이 섞일 수 있을 것이다:
<tt>list_random</tt> could be:


# ["Cold", "pizza", "in", "the", "early", "morning"]
# ["Cold", "pizza", "in", "the", "early", "morning"]
Line 44: Line 44:
# ["early", "morning", "in", "the", "Cold", "pizza"]
# ["early", "morning", "in", "the", "Cold", "pizza"]


원래 목록에서 두 개의 인접한 항목들은 항상 붙어 있음을 눈여겨보라. 여기서 절편길이(stride)가 2로 설정되었다.
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>
<lsl>list list_random = llListRandomize(list01, 6);</lsl>


이 예제에서 목록 list_random은 그냥 본래의 목록이다. 왜냐하면 절편 길이가 본래의 길이 그대로 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.
|constants
|constants
|helpers
|helpers
|also_header
|also_header
|also_functions={{LSL DefineRow/ko||[[llListSort]]|}}
|also_functions={{LSL DefineRow||[[llListSort]]|}}
{{LSL DefineRow/ko||[[llFrand]]|}}
{{LSL DefineRow||[[llFrand]]|}}
|also_tests
|also_tests
|also_articles
|also_articles
|also_footer
|also_footer
|notes=본래의 목록은 변하지 않으며 대신 섞여진 새로운 목록이 생성되는 것에 유의할 것. 결과를 바로 다루지 않는다면 변수에 담는 것이 중요하다.
|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.)
|mode
|mode
|deprecated
|deprecated

Revision as of 00:23, 4 April 2009

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.

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