Algo::SelectRandomWeightedBy

Randomly select an element from a range of elements, weighted by a projection.

Windows
MacOS
Linux

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/Algo/SelectRandomWeighted.h

Include

#include "Algo/SelectRandomWeighted.h"

Syntax

namespace Algo
{
    template<typename RangeType, typename ProjectionType>
    auto Algo::SelectRandomWeightedBy
    (
        RangeType && Range,
        ProjectionType Proj
    )
}

Remarks

Randomly select an element from a range of elements, weighted by a projection. The chance of any element being chosen is its weight / the sum of all the weights in the range. Negative- or zero- weighted elements will not be chosen or count toward the total.

Parameters

Parameter

Description

Range

The range to select from. Can be any iterable type.

Proj

The projection to weight the random selection by. Should yield a numeric type.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss