| This article is a stub. It may be incomplete, unfinished, or have missing parts/sections. If the article can be expanded, please do so! There may be suggestions on its talk page. (March 2022) |
This tutorial explains how to shuffle a list, using an implementation of the Durstenfeld Shuffle.
Code
This script will shuffle the list (list:: list), and also use the variables (index 1), (index 2) which represent the positions of the two items in the list to be swapped in each cycle, and (temp), which is used to temporarily store one of the items being swapped.
set [index1 v] to (1) repeat until <(index1) = ((length of [list v]) - (1)) set [index2 v] to (pick random (index1) to (length of [list v]) set [temp v] to (item (index2) of [list v] replace item (index2) of [list v] with (item (index1) of [list v]) replace item (index1) of [list v] with (temp) change [index1 v] by (1) end