Unreal Engine 5 · Blueprint → C++
Random Integer in Unreal Engine 5 C++
The Blueprint Random Integer node returns a random whole number from 0 up to (but not including) Max. In C++ call UKismetMathLibrary::RandomInteger(Max) after including Kismet/KismetMathLibrary.h.
Blueprint node & C++ equivalent

#include "Kismet/KismetMathLibrary.h"
int32 Max;
int32 Result = UKismetMathLibrary::RandomInteger(Max);What does the Random Integer node do?
Random Integer returns a uniformly random int32 in the half-open range [0, Max), so the result is always less than Max and never negative. It is useful for picking random array indices or selecting among a fixed number of options.
How to use it in C++
Include Kismet/KismetMathLibrary.h and call UKismetMathLibrary::RandomInteger(Max), which returns an int32. The plain FMath::RandRange(0, Max - 1) is a common alternative, though its upper bound is inclusive.
Because the range excludes Max, passing the length of an array gives a valid random index for that array directly.
Frequently asked questions
Does RandomInteger include the Max value in UE5?+
No. UKismetMathLibrary::RandomInteger(Max) returns a value in [0, Max), so Max itself is never returned.
How do I get a random int in Unreal C++?+
Call UKismetMathLibrary::RandomInteger(Max), or use FMath::RandRange(Min, Max) where both bounds are inclusive.