Skip to main content

Mini-language

Not a statistician?

New to simulation? Start with the plain-English getting started guide first — it explains the key concepts in business terms.

The Playground mini-language is a simple expression language for declaring random variables and derived calculations. You write a model in the editor, run 1,000 simulation iterations, and instantly see a histogram of the output.

tip

No account required. Authenticated users can save and reload models.

Core concepts

  • Random variable — a value drawn from a probability distribution each iteration. You declare it with ~ (tilde) followed by a distribution name and parameters.
  • Derived variable — a value computed from other variables using arithmetic. You declare it with = followed by an expression.
  • Output variable — the last variable you declared in your model. The histogram shows its distribution by default. You can also select a different variable from the dropdown.

Syntax

Statements are separated by ;. Each statement is either a random variable declaration or a derived variable declaration.

Variable names must start with a letter and can contain letters, digits, and underscores.

x ~ norm(15, 3);
y ~ uniform(5, 10);
z = x * y;

Random variables

You declare a random variable using ~ and a distribution name:

revenue ~ norm(50000, 8000);
cost_ratio ~ uniform(0.4, 0.6);

Each simulation iteration draws a new sample from the distribution, so the variable takes different values across iterations.

Derived variables

You declare a derived variable using = and a standard arithmetic expression:

profit = revenue - (revenue * cost_ratio);
margin_pct = profit / revenue * 100;

Supported operators:

OperatorMeaningExample
+Additiona + b
-Subtractiona - b
*Multiplicationa * b
/Divisiona / b
**Powera ** b

Variables are resolved in dependency order — you can reference a variable before declaring it, and the system resolves the dependencies automatically.

Comments

Lines starting with # are ignored:

# Revenue model
revenue ~ norm(50000, 8000);

Histogram output

note

The histogram shows the distribution of the last declared variable across all iterations by default. You can select a different variable from the dropdown above the chart.

tip

If you want to visualize a specific variable, declare it last in your model.

The histogram displays 1,000 sampled values (one per simulation iteration). The shape shows you the range, central tendency, and spread of possible outcomes. You can drag the Pr(x < X) line to read off the probability that the output falls below any given value.

Error handling

Parse errors and undefined variable references show as an inline error message below the editor. The histogram clears on error so you can see that the model needs to be fixed before results appear.

How-to guides

Estimate a simple range

This example models a best-case and worst-case scenario and calculates the range between them.

  1. Write the model — declare two uniform variables and a derived variable in the editor. For example:

    low ~ uniform(100, 200);
    high ~ uniform(300, 500);
    range = high - low;
  2. Click Run — the playground executes 1,000 simulation iterations and displays a histogram of the output variable (range) in the right pane.

  3. Read the histogram — examine the shape and spread. You should see the possible range values clustered between 100 and 400, with roughly equal probability across the middle.

Model compound growth

This example combines a fixed initial value with a random monthly growth rate to project customers after one year.

  1. Write the model — declare constants and random variables:

    initial_customers = 1000;
    monthly_growth ~ norm(0.05, 0.01);
    customers_year1 = initial_customers * (1 + monthly_growth) ** 12;
  2. Click Run — the playground simulates each month's growth rate as a random draw from the normal distribution, then compounds 12 times.

  3. Read the histogram — you should see a right-skewed distribution because compounding amplifies higher growth rates. The center should be around 1,800 customers (5% monthly growth compounded over 12 months).

Calculate probability of profit

This example models revenue and costs as random variables, then computes profit as a derived variable.

  1. Write the model — declare revenue, costs, and profit:

    revenue ~ norm(100000, 15000);
    costs ~ norm(80000, 10000);
    profit = revenue - costs;
  2. Click Run — the playground simulates revenue and costs each iteration, then computes profit.

  3. Read the histogram — examine the profit distribution. The center should be around $20,000 (mean revenue of $100k minus mean costs of $80k).

  4. Drag the Pr(x < X) line — drag the vertical line to the value 0 on the x-axis. You should see the probability that profit is negative (a loss). For example, Pr(profit < $0) = 0.13 means there is a 13% chance of a loss.

Reference

Supported distributions

DistributionSyntaxDescription
Normalnorm(mean, std) or normal(mean, std)Symmetric bell-curve. Good for many natural phenomena.
Uniformuniform(low, high) or unif(low, high)Every value in the range is equally likely.
Triangulartriangular(low, mode, high) or tri(low, mode, high)Three-point estimate with a most-likely value.
Lognormallognormal(mean, sigma) or lognorm(mean, sigma)Right-skewed, always positive. Good for costs and time.
Exponentialexponential(rate) or expon(rate)Memoryless waiting times.
Gammagamma(shape, scale)Flexible positive-value distribution.
Betabeta(alpha, beta)Bounded between 0 and 1. Good for probabilities.
Poissonpoisson(rate)Discrete count data.
Binomialbinom(n, p)Number of successes in n independent trials.
Integersintegers(low, high)Uniform random whole number within a range.
Negative Binomialnegbinom(n, p)Number of trials until n successes.
Choicechoice([a, b, c])Picks one value from a list, equally likely.

For detailed descriptions and when to use each distribution, see the Distributions page.

Operator precedence

Expressions follow standard arithmetic precedence:

PrecedenceOperatorsAssociativity
1 (highest)**Right-to-left
2*, /Left-to-right
3 (lowest)+, -Left-to-right

You can use parentheses ( and ) to override precedence.

Supported functions

These built-in functions are available in expressions:

FunctionDescriptionExample
abs(x)Absolute valueabs(profit)
sqrt(x)Square rootsqrt(variance)
log(x)Natural logarithmlog(odds)
exp(x)Exponential (e^x)exp(growth_rate)
min(a, b)Minimum of two valuesmin(revenue, budget)
max(a, b)Maximum of two valuesmax(profit, 0)

Next steps

  • Distributions — detailed descriptions of all supported distributions and when to use each one.