How to Shuffle a List
Материал из Поле цифровой дидактики
This tutorial explains how to shuffle some items in a list.
Variables
(item that had its position shuffled) (# of item that is being shuffled) (shuffle is) (repeat) (items that already had their positions shuffled::list) (shuffle between::list)
Full Code
when green flag clicked set [shuffled is v] to [] delete all of [items that already had their positions shuffled v] delete all of [shuffle between v] ask [How many items do you want to be shuffled?] and wait set [repeat v] to (answer) repeat (repeat) ask [Input an item to be shuffled:] and wait add (answer) to [shuffle between v] end repeat (length of [shuffle between v]) set [# of item that is being shuffled v] to (pick random (1) to (length of [shuffle between v]) repeat until <not <[items that already had their positions shuffled v] contains (item (# of item that is being shuffled) of [shuffle between v])>> set [# of item that is being shuffled v] to (pick random (1) to (length of [shuffle between v]) end set [item that had its position shuffled v] to (item (# of item that is being shuffled) of [shuffle between v]) delete (item # of (item that had its position shuffled) in [shuffle between v]) of [shuffle between v] insert (item that had its position shuffled) at (pick random (1) to ((length of [shuffle between v]) + (1))) of [shuffle between v] add (item that had its position shuffled) to [items that already had their positions shuffled v] end set [shuffle is v] to (item (1) of [shuffle between v])