Hands-On Usage
randomize_temp_variable is commonly used in event outcomes that require introducing randomness, such as randomizing battle casualties, generating random resource reward amounts, or determining random event branch weights. Compared to hardcoding fixed values, it makes mod results more unpredictable and enhances gameplay experience.
# Randomly generate a political power reward in an event option (uniform distribution between 0~5)
option = {
name = my_event.option_a
randomize_temp_variable = {
var = temp_pp_gain
distribution = uniform
min = 0
max = 5
}
round_temp_variable = temp_pp_gain
add_political_power = temp_pp_gain
}
Synergy
[round_temp_variable](/wiki/effect/round_temp_variable): The uniform distribution produces floating-point numbers; you typically need to round first before passing to integer-only effects (such as add_political_power), otherwise unexpected behavior may occur.
[clamp_temp_variable](/wiki/effect/clamp_temp_variable): After generating a random value, use clamp to constrain it within the safe range permitted by your game logic, preventing extreme values from breaking balance.
[add_to_temp_variable](/wiki/effect/add_to_temp_variable): Stack a fixed offset on top of the randomized base value to implement the common "random value + guaranteed minimum" design pattern.
[check_variable](/wiki/trigger/check_variable): After randomization, you typically need to branch execution based on the result; pair with check_variable inside if blocks to test which interval the random result falls into.
Common Pitfalls
- Forgetting to round the result: The
uniform distribution produces floating-point numbers by default. If you pass temp_variable directly to effects that only accept integers (such as add_manpower), the script won't error but will silently truncate or produce unexpected values—always call round_temp_variable first.
- Omitting max in binomial / lambda in poisson:
binomial requires max to be specified when min is set; poisson always requires lambda. Omitting these fields won't produce obvious error messages, but distribution parameters will revert to default behavior, causing random results to be completely misaligned with your expectations.