Well, I went searching the whole engine code just in case I would find a solution, and the only thing I found was more or less the same in file
UE_4.22\Engine\Source\Runtime\AnimGraphRuntime\Private\AnimNodes\AnimNode_RandomPlayer.cpp(322)
// Shuffle the list
const int32 NumShuffles = ShuffleList.Num() - 1;
for(int32 i = 0 ; i < NumShuffles ; ++i)
{
int32 SwapIdx = RandomStream.RandRange(i, NumShuffles);
ShuffleList.Swap(i, SwapIdx);
}
If Epic does it this way, maybe they don’t have a better one yet.
Math and container operation node functions are usually in kismet libraries, as C++ equivalents are not reflected.
You generally should shuffle array yourself optimized to specific case as Koulounil suggests, but if you really want to use exact same code as in blueprint use this function… which is not much diffrent from what Koulounil shown:
void UKismetArrayLibrary::GenericArray_Shuffle(void* TargetArray, const UArrayProperty* ArrayProp)
{
if (TargetArray)
{
FScriptArrayHelper ArrayHelper(ArrayProp, TargetArray);
int32 LastIndex = ArrayHelper.Num() - 1;
for (int32 i = 0; i <= LastIndex; ++i)
{
int32 Index = FMath::RandRange(i, LastIndex);
if (i != Index)
{
ArrayHelper.SwapValues(i, Index);
}
}
}
}