How to Shuffle a List with Scripting
by BerkaZerka
<< All Articles
|
Print
How to Shuffle a List with Scripting
You can use Advanced Editor Scripting to randomize the order of list (without duplicates) using the following method.
First, define your list.
Whether Cards, Items, Encounter Numbers, etc. In this example, we'll use Ten Sandwich Items (because sandwich).
1. Ham
2. Salami
3. Bologna
4. Cheese
5. Lettuce
6. Onion
7. Tomato
8. Pickle
9. Mustard
10. Mayo
---
Next, Assign your List to Variables (One Variable for each Item in your List).
%LISTITEM1 := 1
%LISTITEM2 := 2
%LISTITEM3 := 3
%LISTITEM4 := 4
%LISTITEM5 := 5
%LISTITEM6 := 6
%LISTITEM7 := 7
%LISTITEM8 := 8
%LISTITEM9 := 9
%LISTITEM10 := 10
---
You'll also need to determine your output Variables. We'll Use %LAYER1, %LAYER2, and %LAYER3 (because I want to make a 3 layer sandwich, using items from the above list).
My On-Page Script will reflect this:
BZ's Three Layer Sandwich -
%%LAYER1%=%1%Ham%%%%LAYER1%=%2%Salami%%%%LAYER1%=%3%Bologna%%%%LAYER1%=%4%Cheese%%%%LAYER1%=%5%Lettuce%%%%LAYER1%=%6%Onion%%%%LAYER1%=%7%Tomato%%%%LAYER1%=%8%Pickle%%%%LAYER1%=%9%Mustard%%%%LAYER1%=%10%Mayo%%, %%LAYER2%=%1%Ham%%%%LAYER2%=%2%Salami%%%%LAYER2%=%3%Bologna%%%%LAYER2%=%4%Cheese%%%%LAYER2%=%5%Lettuce%%%%LAYER2%=%6%Onion%%%%LAYER2%=%7%Tomato%%%%LAYER2%=%8%Pickle%%%%LAYER2%=%9%Mustard%%%%LAYER2%=%10%Mayo%%, %%LAYER3%=%1%Ham%%%%LAYER3%=%2%Salami%%%%LAYER3%=%3%Bologna%%%%LAYER3%=%4%Cheese%%%%LAYER3%=%5%Lettuce%%%%LAYER3%=%6%Onion%%%%LAYER3%=%7%Tomato%%%%LAYER3%=%8%Pickle%%%%LAYER3%=%9%Mustard%%%%LAYER3%=%10%Mayo%%.
---
Then we Randomize, Drawing one Item from the List into each Output Variable (or Layer of the sandwich). Three Results will require 3 draws from the list -
%SHUF := 1D10
IF %SHUF = 1 THEN BEGIN %LAYER1 := %LISTITEM1 %LISTITEM1 := %LISTITEM10 END
IF %SHUF = 2 THEN BEGIN %LAYER1 := %LISTITEM2 %LISTITEM2 := %LISTITEM10 END
IF %SHUF = 3 THEN BEGIN %LAYER1 := %LISTITEM3 %LISTITEM3 := %LISTITEM10 END
IF %SHUF = 4 THEN BEGIN %LAYER1 := %LISTITEM4 %LISTITEM4 := %LISTITEM10 END
IF %SHUF = 5 THEN BEGIN %LAYER1 := %LISTITEM5 %LISTITEM5 := %LISTITEM10 END
IF %SHUF = 6 THEN BEGIN %LAYER1 := %LISTITEM6 %LISTITEM6 := %LISTITEM10 END
IF %SHUF = 7 THEN BEGIN %LAYER1 := %LISTITEM7 %LISTITEM7 := %LISTITEM10 END
IF %SHUF = 8 THEN BEGIN %LAYER1 := %LISTITEM8 %LISTITEM8 := %LISTITEM10 END
IF %SHUF = 9 THEN BEGIN %LAYER1 := %LISTITEM9 %LISTITEM9 := %LISTITEM10 END
IF %SHUF = 10 THEN %LAYER1 := %LISTITEM10
%SHUF := 1D9
IF %SHUF = 1 THEN BEGIN %LAYER2 := %LISTITEM1 %LISTITEM1 := %LISTITEM9 END
IF %SHUF = 2 THEN BEGIN %LAYER2 := %LISTITEM2 %LISTITEM2 := %LISTITEM9 END
IF %SHUF = 3 THEN BEGIN %LAYER2 := %LISTITEM3 %LISTITEM3 := %LISTITEM9 END
IF %SHUF = 4 THEN BEGIN %LAYER2 := %LISTITEM4 %LISTITEM4 := %LISTITEM9 END
IF %SHUF = 5 THEN BEGIN %LAYER2 := %LISTITEM5 %LISTITEM5 := %LISTITEM9 END
IF %SHUF = 6 THEN BEGIN %LAYER2 := %LISTITEM6 %LISTITEM6 := %LISTITEM9 END
IF %SHUF = 7 THEN BEGIN %LAYER2 := %LISTITEM7 %LISTITEM7 := %LISTITEM9 END
IF %SHUF = 8 THEN BEGIN %LAYER2 := %LISTITEM8 %LISTITEM8 := %LISTITEM9 END
IF %SHUF = 9 THEN %LAYER2 := %LISTITEM9
%SHUF := 1D8
IF %SHUF = 1 THEN BEGIN %LAYER3 := %LISTITEM1 %LISTITEM1 := %LISTITEM8 END
IF %SHUF = 2 THEN BEGIN %LAYER3 := %LISTITEM2 %LISTITEM2 := %LISTITEM8 END
IF %SHUF = 3 THEN BEGIN %LAYER3 := %LISTITEM3 %LISTITEM3 := %LISTITEM8 END
IF %SHUF = 4 THEN BEGIN %LAYER3 := %LISTITEM4 %LISTITEM4 := %LISTITEM8 END
IF %SHUF = 5 THEN BEGIN %LAYER3 := %LISTITEM5 %LISTITEM5 := %LISTITEM8 END
IF %SHUF = 6 THEN BEGIN %LAYER3 := %LISTITEM6 %LISTITEM6 := %LISTITEM8 END
IF %SHUF = 7 THEN BEGIN %LAYER3 := %LISTITEM7 %LISTITEM7 := %LISTITEM8 END
IF %SHUF = 8 THEN %LAYER3 := %LISTITEM8
Note that each draw, takes the drawn value and places it outside the range of the next draw to prevent duplicate draws, while bringing the outside value of the next draw into the draw range.
So, If my rolls end up, say 4, 7, 3
My On Page Script will read: "BZ's Three Layer Sandwich - Cheese, Tomato, Bologna."
---
You can use other types of output too, such as Pages -
IF %LAYER1 = 8 THEN $DEST := @P10
IF %LAYER2 = 8 THEN $DEST := @P50
IF %LAYER3 = 8 THEN $DEST := @P100
In other words, if you are lucky enough to get a pickle on your sandwich, then prepare yourself for various results (depending on which layer it shows up in).
Good luck!