UKismetArrayLibrary::Array_Random
#include "Kismet/KismetArrayLibrary.h"
Access: public
Specifiers: staticBlueprintPureCustomThunk
Description
Picks a random element from an array using the global random stream and returns both the value and its index.
Caveats & Gotchas
- • If TargetArray is empty, OutIndex is set to -1 and OutItem is left at its default-constructed value rather than the function erroring.
- • Uses global engine randomness (FMath::Rand), so results are not reproducible between runs — use Array_RandomFromStream with an FRandomStream for deterministic output.
- • Displayed in Blueprint as 'Random Array Item' with CompactNodeTitle 'RANDOM'.
Signature
static void Array_Random(const TArray<int32>& TargetArray, int32& OutItem, int32& OutIndex); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| TargetArray | const TArray<int32>& | The array to pick from. | — |
| OutItem | int32& | Output parameter filled with a copy of the randomly chosen element. | — |
| OutIndex | int32& | Output parameter filled with the index of the chosen element, or -1 if the array is empty. | — |
Return Type
void Example
Pick a random element C++
TArray<int32> Values = { 1, 2, 3, 4 };
int32 Item, Index;
UKismetArrayLibrary::Array_Random(Values, Item, Index);
// Item is one of {1,2,3,4}; Index is its position in Values See Also
Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?