# How do I model a time that is a fixed part plus a random part?

A repair is a fixed diagnosis followed by a random fix, and no single distribution says that. CustomExpression takes any expression. The script uses `2 + EXPO(3)` as the bay's repair time.

```python
from nagasim import build as nb

# A repair is a fixed 2-minute diagnosis plus an exponential fix with a mean of 3 minutes. No single
# distribution says that, but an expression does. UNIF, EXPO, NORM, TRIA and DISC are available.
repair = nb.CustomExpression(expression="2 + EXPO(3)")

m = nb.Model(time_limit=4000, warmup=0)
m.add_resource(name="Bay")
cars = m.create(distribution=nb.Exponential(rate=1 / 8))
cars >> m.process(resource_name="Bay", distribution=repair) >> m.dispose()

results = m.run(replications=10, seed=1)
print(f"bay busy {results.kpi('resource/Bay/Usage % (snapshot)'):.0f}% (mean repair 5 minutes in 8 is 62%)")

```

Save it as `recipe-formula-time.py` and run it with `python`. The script seeds itself, so the numbers below are the same on your machine.

```text
bay busy 63% (mean repair 5 minutes in 8 is 62%)

```

## How it works

1. `CustomExpression` evaluates its text each time a time is needed, so `EXPO`, `UNIF`, `NORM`, `TRIA` and `DISC` are all available.
2. The mean of `2 + EXPO(3)` is 5 minutes, so one car every 8 minutes loads the bay to about 62%.
3. It cannot be fitted from data, so use it for a known structure and a named family for a fitted shape.

## Elements used

- Distributions: [CustomExpression](../../reference/distributions/custom-expression.md), [Exponential](../../reference/distributions/exponential.md).
- Blocks: [CREATE](../../reference/blocks/create.md), [PROCESS](../../reference/blocks/process.md), [DISPOSE](../../reference/blocks/dispose.md).
- Python: [`Model`](../../reference/api/Model.md).

Back to all [recipes](index.md).
