Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
RandomShuffle.h
Go to the documentation of this file.
1
// Copyright Epic Games, Inc. All Rights Reserved.
2
3
#
pragma
once
4
5
#
include
"Math/UnrealMathUtility.h"
6
#
include
"Templates/UnrealTemplate.h"
7
8
namespace
Algo
9
{
10
/**
11
* Randomly shuffle a range of elements.
12
*
13
* @param Range Any contiguous container.
14
*/
15
template
<
typename
RangeType>
16
void
RandomShuffle
(RangeType& Range)
17
{
18
auto
Data
=
GetData
(
Range
);
19
20
using
SizeType
=
decltype
(
GetNum
(
Range
));
21
const
SizeType
Num
=
GetNum
(
Range
);
22
23
for
(
SizeType
Index
= 0;
Index
<
Num
- 1; ++
Index
)
24
{
25
// Get a random integer in [Index, Num)
26
const
SizeType
RandomIndex
=
Index
+ (
SizeType
)
FMath
::
RandHelper64
(
Num
-
Index
);
27
if
(
RandomIndex
!=
Index
)
28
{
29
Swap
(
Data
[
Index
],
Data
[
RandomIndex
]);
30
}
31
}
32
}
33
}
Algo
Definition
Heapify.h:12
Algo::RandomShuffle
void RandomShuffle(RangeType &Range)
Definition
RandomShuffle.h:16
Downloads
ArkServerAPI_NEW
ASA
AsaApi
AsaApi
Core
Public
API
UE
Algo
RandomShuffle.h
Generated by
1.10.0