UKismetMathLibrary::RandomInteger
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticBlueprintPure
Description
Returns a uniformly distributed random integer in the range [0, Max - 1]. Uses the global non-deterministic random stream.
Caveats & Gotchas
- • The parameter is named 'Exclusive Max' in Blueprint — the returned value is never equal to Max. This is a common off-by-one trap: RandomInteger(10) returns 0–9, not 0–10. Use RandomIntegerInRange(0, 10) for an inclusive upper bound.
- • This function is marked NotBlueprintThreadSafe because it writes to a shared global RNG state. Calling it from a Parallel For or multi-threaded Blueprint will produce race conditions. Use FMath::RandHelper with a per-thread FRandomStream instead.
Signature
static UE_INL_API int32 RandomInteger(UPARAM(DisplayName = "Exclusive Max") int32 Max); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Max | int32 | Exclusive upper bound. The result is in [0, Max-1]. | — |
Return Type
int32 Example
Pick a random array index C++
TArray<AActor*> Targets;
// ...populate Targets...
if (Targets.Num() > 0)
{
int32 Index = UKismetMathLibrary::RandomInteger(Targets.Num());
AActor* Chosen = Targets[Index];
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?