Verse Library verse

01 Snippet

Randomly rearranges an input array using the Fisher-Yates algorithm for unbiased shuffling.

extracted-snippets/community/snippets/2reL/fortnite-shuffle-the-array/01-snippet.verse

# Source URL: https://dev.epicgames.com/community/snippets/2reL/fortnite-shuffle-the-array
# Local doc:  epic-docs/community/snippets/2reL/fortnite-shuffle-the-array.md
FisherYatesShuffle(Source:[]int)<transacts>:[]int =
var ShaffleDeck :[]int = Source
for:
Head := 0..ShaffleDeck.Length-1
RandomNumber := GetRandomInt(Head, ShaffleDeck.Length-1)
Result := ShaffleDeck[RandomNumber]
set ShaffleDeck[RandomNumber] = ShaffleDeck[Head]
do:
Result

Comments

    Sign in to vote, comment, or suggest an edit. Sign in