Random Permutation Picker Device
41,520 Views
-
using { /Fortnite.com/Devices } using { /Verse.org/Random } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # The random_permutation_picker device generates a random permutation of # its Choices and then picks them one at a time, without item repetition, with Pick. # When the last choice has been picked, a new permutation is generated. random_permutation_picker_device := class(creative_device): @editable PickButton:button_device = button_device{} # The Choices array is the set of elements to be picked. @editable var<private> Choices:[]switch_device = array{} var<private> PickStartIndex<private>:int=0 # Pick one of the Choices, without repetition. # The algorithm uses a form of the Fisher-Yates shuffle to generate a random permutation. # See https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle # for a description of the Fisher-Yates shuffle algorithm. Pick<public>()<transacts><decides>:switch_device= # Imagine a hat with all the Choices in it. # The hat is full at the start of the permutation. # PickStartIndex is the index of the first element in the hat. # We pick an element from the hat, remove it from the hat, and return it. # When the hat is empty, we refill it and start a new permutation.
You're reading a preview
The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.
Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.