Distributions¶
Sample a number each time the expression is evaluated. Arguments are required
numeric expressions. A wrong argument count is a link error. A draw is
allowed only at moments that permit sampling: const expressions and hold
headers cannot draw. See evaluation moments.
Distribution index¶
| Distribution | Parameters | Mean | Description |
|---|---|---|---|
~exp(mean) |
mean: expr |
mean |
Exponential. |
~det(x) |
x: expr |
x |
Constant value. |
~uniform(lo, hi) |
lo, hi: expr |
(lo + hi) / 2 |
Continuous uniform. |
~erlang(k, mean) |
k, mean: expr |
mean |
Sum of exponential phases. |
~h2(mean, cv2) |
mean, cv2: expr |
mean |
Balanced two-phase hyperexponential. |
~bernoulli(p) |
p: expr |
p |
0 or 1. |
exp¶
Parameters: mean is the mean duration in the consumer's unit. Use a
positive finite mean for an exponential duration.
Returns: an exponential draw of mean mean and squared coefficient of
variation (CV²) 1. The parameter is a mean, not a rate.
det¶
Parameters: x is the value to return.
Returns: exactly x. It is still a draw expression for validation, so
it cannot be used where draws are forbidden.
uniform¶
Parameters: lower and upper bounds lo and hi. Use finite ordered
bounds for a bounded duration.
Returns: lo + (hi - lo) * U, where U is uniform in [0, 1).
Equal bounds return that value; floating-point rounding applies at the
endpoints. Mean: (lo + hi) / 2.
erlang¶
Parameters: k is the phase count, rounded down and taken to be at
least 1. mean is the total mean, not the mean of each phase; use a positive
finite value for a duration.
Returns: the sum of k independent exponential draws, each with mean
mean / k. Its CV² is 1 / k after the phase-count conversion.
h2¶
Parameters: mean is the total mean; use a positive finite value for a
duration. cv2 is the squared coefficient of variation, taken to be at least
1. For cv2 = 1, the law is exponential.
Returns: a draw from the balanced two-phase hyperexponential law.
For v = max(cv2, 1) and p = (1 + sqrt((v - 1) / (v + 1))) / 2, choose
an exponential of mean mean / (2*p) with probability p, otherwise one
of mean mean / (2*(1-p)).
bernoulli¶
Parameters: p is a probability in [0, 1].
Returns: 1 with probability p, otherwise 0. The form
branch with (p) uses this draw; see branch.
Validation and reproducibility¶
The domains above describe the intended distributions, not a guarantee that every invalid parameter is rejected at link time. The consuming construct validates its own requirements: for example, a renewal gap must be positive and finite when drawn or the run fails.
The run's seed initializes separate streams for arrivals, workload draws,
session statements and eviction keys. Workload draws are keyed by session
and turn: unchanged draw expressions with the same inputs reproduce the same
values across scheduling policies. See workloads.
Examples¶
A complete program with bursty arrivals and Erlang service times:
fn main() {
stage svc : fifo;
workload {
arrive renewal(~h2(2, 4));
}
server {
set t0 = now;
run svc (cost(svc, ~erlang(4, 1)));
observe response = now - t0;
}
}
Save as model.sq, then run: