Skip to main content

With % Chance

Changes the probability that the code on the hook will be executed.

With % Chance block

Description

The With % Chance block changes the probability that the code on the hook will be executed. This is a code block from the Logic drawer.

Usage

Changes the probability that the code on the hook will be executed.

Syntax

Inputs in this block:

  • A number

Example

The model below shows a contagious disease. On contact with a 'sneeze' agent, healthy agents have a 40% chance of contracting the disease (becoming red).

With % Chance example code
  • Random Decimal - Generates a random decimal between 0 and 1
  • If - Tests a condition