RealDocs

UKismetMathLibrary::RandomBoolWithWeightFromStream

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

Description

Returns true with the given probability using a caller-supplied FRandomStream instead of the global RNG. Use this when you need reproducible, seedable random decisions — such as procedural generation or gameplay replay.

Caveats & Gotchas

  • FRandomStream is taken by const reference and the stream IS mutated internally (the float it reads advances the stream state). Despite the const ref signature, calling this function changes the stream's internal counter — downstream calls on the same stream will produce different values.
  • To get truly reproducible sequences, initialize the FRandomStream with a fixed seed before the first call and avoid calling any other function on the same stream between uses.

Signature

static ENGINE_API bool RandomBoolWithWeightFromStream(const FRandomStream& RandomStream, float Weight);

Parameters

Name Type Description Default
RandomStream const FRandomStream& The seeded random stream to draw from. Does not advance the stream's seed (it uses a non-mutating call).
Weight float Probability of returning true, in the range 0.0–1.0.

Return Type

bool

Example

Seeded procedural loot generation C++
FRandomStream LootStream(RoomSeed);
bool bHasRareItem = UKismetMathLibrary::RandomBoolWithWeightFromStream(LootStream, 0.1f);
bool bHasCommonItem = UKismetMathLibrary::RandomBoolWithWeightFromStream(LootStream, 0.8f);

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.