Wiki

effect · random

Definition

  • Supported scope:any
  • Supported target:none

Description

a random effect

Hands-On Notes

Hands-on notes are AI-generated and checked against the vanilla command vocabulary — treat them as a starting point, not authoritative reference. The definition above is the game's own documentation.

Hands-On Usage

random is an effect used to execute a randomized outcome in mods, commonly seen in random event triggers, probabilistic reward/penalty distribution, or chance-based state changes. For example, when you want a certain probability to grant a nation a focus or trigger subsequent effects within a decision or event option, it can be nested inside random_list, or used independently to produce a single random behavior.

# Using random in an event option to execute a randomized effect
option = {
    name = my_event.1.a
    random = {
        chance = 50
        add_victory_points = {
            province = 3340
            value = 5
        }
    }
}

Synergy

  • [random_list](/wiki/effect/random_list): random_list provides multi-branch weighted randomization, while random handles single probability checks; they complement each other and suit different granularities of random logic design.
  • [hidden_effect](/wiki/effect/hidden_effect): Wrapping random inside hidden_effect executes the randomized effect silently, avoiding extraneous tooltip text in the event interface.
  • [if](/wiki/effect/if): Pairing if conditionals within random enables compound logic such as "trigger with some probability, but only if additional conditions are met after triggering."
  • [custom_effect_tooltip](/wiki/effect/custom_effect_tooltip): Since random's randomness is not intuitive in the UI, combining it with custom_effect_tooltip can display probability explanations to players and improve readability.

Common Pitfalls

  1. Missing the chance field: random requires chance to specify trigger probability (typically an integer from 0–100); omitting or misspelling the field name may cause the effect to never trigger or always trigger. Beginners often confuse this with random_list's weighting syntax.
  2. Misuse in trigger blocks: random is an effect command and can only be used in execution blocks (such as immediate, option, or hidden_effect), not in trigger or limit blocks. Mixing them causes script errors or silent logic failure.