Simulate a compound event or conditional probability (Monte Carlo)
simulate_monte_carloActually draws random samples from real distributions and counts outcomes, instead of a model guess about a probability. Declare named random variables (uniform, normal, bernoulli, binomial, poisson, exponential, discrete), an "event" boolean expression over those variable names (e.g. "a > 0.5 && b == 1"), and an optional "condition" expression to estimate a conditional probability P(event | condition) by rejection sampling. Event/condition expressions are parsed and evaluated by a small built-in interpreter (arithmetic, comparisons, &&/||/!, min/max/abs) — no arbitrary code execution. Returns the estimated probability, a 95% confidence interval, and the seed used (pass the same seed back to reproduce the exact result). Costs $0.03 USDC (Base) per call.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| seed | No | Optional PRNG seed for a reproducible run. If omitted, a random seed is generated and returned in the output. | |
| event | Yes | Boolean expression over the variable names, evaluated each trial (e.g. "a + b > 10", "x == 1 && y < 0.2"). | |
| trials | No | Number of trials to run. Default 10000, between 100 and 100000. | |
| condition | No | Optional boolean expression; if given, the result is P(event | condition), estimated only over trials where this is true. | |
| variables | Yes | Random variables to sample each trial. Max 10. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| error | Yes | Error or warning message. null if none. | |
| valid | Yes | false if the input (variables, expressions, limits) was invalid. | |
| seed_used | Yes | The PRNG seed used — pass it back as `seed` to reproduce this exact result. | |
| trials_run | Yes | Number of trials actually simulated (0 if valid is false). | |
| probability | Yes | Estimated P(event) or P(event | condition). null if invalid, or if condition matched zero trials. | |
| standard_error | Yes | Estimated standard error of the probability estimate. | |
| event_successes | Yes | Number of trials (or condition-matching trials) where event was true. | |
| condition_successes | Yes | Number of trials where condition was true. null if no condition was given. | |
| confidence_interval_95 | Yes | Approximate 95% confidence interval [low, high] via the normal approximation. |