Skip to content

random_util

Source: base/tealdef/scripts/random_util.d.tl

Notes

Types of /scripts/random_util.tl (RandomUtil) for weighted random selection.

RandomUtil

record global base/tealdef/scripts/random_util.d.tl:3

global record RandomUtil

Load: local random_util = ug_require "/scripts/random_util.tl"

Notes

Random helpers returned by ug_require "/scripts/random_util.tl".

Functions

pickRandomWeightedItem<T>({{T, number}}) : T base/tealdef/scripts/random_util.d.tl:4

Call as random_util.pickRandomWeightedItem

Notes

Picks one item at random, with probability proportional to its weight.

Parameter Type Description
#1 {{T, number}} List of {item, weight} pairs; weights are non-negative numbers.

Returns T: The chosen item.

Used in the base game: 4 times in 4 files

base/content/game_mechanics/game_mechanics/subventions/deliver_workers/deliver_workers.script.tl:144

local targetIndustry = random_util.pickRandomWeightedItem(nonBoostedConnected)
base/content/game_mechanics/game_mechanics/subventions/deliver_cargo_town/deliver_cargo_town.script.tl:288
local townEntityAndCargoTypeId = random_util.pickRandomWeightedItem(allTowns)
base/content/game_mechanics/game_mechanics/subventions/deliver_passengers/deliver_passengers.script.tl:198
local pair = random_util.pickRandomWeightedItem(weightedPairs) as Pair
mods/release/urbangames_campaign_mission_06/content/subventions/subventions/deliver_visitors/deliver_visitors.script.tl:145
local targetLandmark = random_util.pickRandomWeightedItem(getAllEmptyLandmarks())