Created
May 1, 2020 17:18
-
-
Save KaosSpectrum/520b1521c898801c21f7ba3f90d70fcc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <class T> | |
| void ShuffleArray(T& InArray) | |
| { | |
| const int32 LastIndex = InArray.Num() - 1; | |
| for (int32 i = 0; i < LastIndex; ++i) | |
| { | |
| int32 Index = FMath::RandRange(0, LastIndex); | |
| if (i != Index) | |
| { | |
| InArray.Swap(i, Index); | |
| } | |
| } | |
| } | |
| template <class T> | |
| void ShuffleArray(T& InArray, const FRandomStream& InRandomStream) | |
| { | |
| const int32 LastIndex = InArray.Num() - 1; | |
| for (int32 i = 0; i < LastIndex; ++i) | |
| { | |
| int32 Index = InRandomStream.RandRange(0, LastIndex); | |
| if (i != Index) | |
| { | |
| InArray.Swap(i, Index); | |
| } | |
| } | |
| } | |
| template <class T> | |
| void ShuffleArray(T& InArray, int32 Seed) | |
| { | |
| const FRandomStream Stream{Seed}; | |
| const int32 LastIndex = InArray.Num() - 1; | |
| for (int32 i = 0; i < LastIndex; ++i) | |
| { | |
| int32 Index = Stream.RandRange(0, LastIndex); | |
| if (i != Index) | |
| { | |
| InArray.Swap(i, Index); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment