RealDocs

UKismetMathLibrary::RandomBoolWithWeight

function Engine Blueprint Since 4.0
#include "Kismet/KismetMathLibrary.h"
Access: public Specifiers: staticBlueprintPureNotBlueprintThreadSafe

Description

Returns true with the given probability and false otherwise. A Weight of 0.6 returns true approximately 60% of the time, making it convenient for tunable random outcomes without manual threshold comparisons.

Caveats & Gotchas

  • Weight is clamped to [0.0, 1.0] internally — passing values outside that range will not crash but will behave as 0 or 1 (always false or always true).
  • Like RandomBool, this uses the global RNG and is marked NotBlueprintThreadSafe; use RandomBoolWithWeightFromStream for deterministic or multithreaded scenarios.

Signature

static ENGINE_API bool RandomBoolWithWeight(float Weight);

Parameters

Name Type Description Default
Weight float Probability of returning true, in the range 0.0–1.0. Default Blueprint hint is 0.5.

Return Type

bool

Example

30% chance to spawn a bonus item C++
if (UKismetMathLibrary::RandomBoolWithWeight(0.3f))
{
    SpawnBonusItem(GetActorLocation());
}

Tags

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.