RealDocs

FMath::RandRange

function Core Since unknown
#include "Math/UnrealMathUtility.h"
Access: public Specifiers: static

Description

Returns a random integer in the inclusive range [Min, Max]. A float overload (FMath::FRandRange) exists for continuous ranges.

Signature

static inline int32 RandRange(int32 Min, int32 Max)

Parameters

Name Type Description Default
Min int32 Minimum value of the range, inclusive.
Max int32 Maximum value of the range, inclusive.

Return Type

int32

Caveats & Gotchas

  • The integer overload is inclusive on both ends — RandRange(0, 1) returns either 0 or 1 with equal probability.
  • When passing float literals, the compiler will select the float overload (FRandRange) rather than int32. Prefer explicit int32 casts or use FMath::FRandRange directly to make intent clear.
  • Uses a global seed shared across the process. For deterministic or per-instance random sequences (AI, procedural generation), use FRandomStream instead.
  • Not thread-safe — avoid calling from multiple threads simultaneously without your own synchronisation.

Example

Random loot drop and random spawn offset C++
// Random integer in [1, 6] — simulating a dice roll
int32 DiceRoll = FMath::RandRange(1, 6);

// Random float in [0.5, 2.0] — using the float overload
float RandomPitch = FMath::RandRange(0.5f, 2.0f);

// Deterministic version using FRandomStream (preferred for reproducible results)
FRandomStream Stream(42);
int32 DeterministicRoll = Stream.RandRange(1, 6);

See Also

Tags

Version History

Introduced in: unknown

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.