v1.5.0 release: LyrebirdRandom + Live Scratch editor

LyrebirdRandom scalar distribution sampling (seedable value type + shared
Random) with DistributionKind.sample dispatcher. Live Scratch editor: rename to
LyrebirdScratch, App Support artifact staging, Format Code (⌥⌘F), Render to File
(⌥⌘R offline CAF), line-number gutter, manual completion, Foundation in snippets,
scroll-jump fix, scheduling/NRT docs.
This commit is contained in:
2026-07-22 07:53:12 -07:00
parent 8519cabe42
commit 62b2f5dbec
43 changed files with 2249 additions and 376 deletions
@@ -0,0 +1,84 @@
// DistributionKindSampling.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
extension DistributionKind {
/// Draw one sample from this distribution, advancing `rng` (a xorshift64
/// state). This is the canonical mapping from a ``DistributionKind`` case to
/// its sampler — the same mapping ``TemporalTendency`` and
/// ``DemandTemporalTendency`` use — exposed for one-shot scalar draws.
///
/// The `parX` / `parY` / `parA` / `parB` roles are per-distribution; see the
/// parameter table on ``DistributionKind``. `parA` / `parB` are optional and
/// fall back to each distribution's own default (beta shapes default to `2`;
/// Cauchy's positive-only flag defaults off).
///
/// RT-safe: pure arithmetic, no allocation. For an ergonomic seedable wrapper
/// with named per-distribution methods, use ``LyrebirdRandom``.
///
/// - Parameters:
/// - parX: First parameter (e.g. `lo`, density, dispersion, dev — per the table).
/// - parY: Second parameter (e.g. `hi`, mean — per the table). Ignored by
/// single-parameter distributions. Defaults to `1` (matching
/// ``TemporalTendency`` / ``DemandTemporalTendency``), so an omitted
/// `parY` on a range distribution gives `[lo, 1]` rather than a
/// degenerate `[lo, 0]` — but supply it explicitly for a real range.
/// - parA: Third parameter (beta `alpha`, Cauchy positive-only flag).
/// `nil` uses the distribution's default.
/// - parB: Fourth parameter (beta `beta`). `nil` uses the default.
/// - rng: xorshift64 state, advanced in place.
/// - Returns: One sample.
public func sample(
parX: Double,
parY: Double = 1,
parA: Double? = nil,
parB: Double? = nil,
using rng: inout UInt64
) -> Double {
let betaDefaultAlpha: Double = 2.0
let betaDefaultBeta: Double = 2.0
switch self {
case .uniform:
return _sampleUniform(lo: parX, hi: parY, rng: &rng)
case .lpRand:
return _sampleLpRand(lo: parX, hi: parY, rng: &rng)
case .hpRand:
return _sampleHpRand(lo: parX, hi: parY, rng: &rng)
case .meanRand:
return _sampleMeanRand(lo: parX, hi: parY, rng: &rng)
case .expRand:
return _sampleExpRand(lo: parX, hi: parY, rng: &rng)
case .exponential:
return _sampleExponential(density: parX, rng: &rng)
case .gamma:
return _sampleGamma(shape: parX, rng: &rng)
case .laplace:
return _sampleLaplace(dispersion: parX, rng: &rng)
case .alaplace:
return _sampleALaplace(dispersion: parX, rng: &rng)
case .hcos:
return _sampleHcos(dispersion: parX, rng: &rng)
case .logistic:
return _sampleLogistic(dispersion: parX, rng: &rng)
case .poisson:
return _samplePoisson(mean: parX, rng: &rng)
case .arcsin:
return _sampleArcsin(dispersion: parX, rng: &rng)
case .betaRand:
return _sampleBetaRand(
lo: parX,
hi: parY,
alpha: parA ?? betaDefaultAlpha,
beta: parB ?? betaDefaultBeta,
rng: &rng
)
case .cauchy:
return _sampleCauchy(mean: parX, spread: parY, posOnly: (parA ?? 0) > 0, rng: &rng)
case .gauss:
return _sampleGauss(dev: parX, mean: parY, rng: &rng)
}
}
}
@@ -0,0 +1,168 @@
// LyrebirdRandom.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
/// A seedable scalar random source over Lyrebird's distribution family.
///
/// Where ``TemporalStream`` / ``Pattern`` produce *sequences* and the noise
/// generators produce *signals*, `LyrebirdRandom` answers the "give me one
/// value" case: a single draw from a uniform range, a Gaussian, a Laplace, and
/// so on. It owns a xorshift64 state, so a given `seed` produces a fully
/// reproducible stream of draws — which is what musical use wants.
///
/// ```swift
/// var r = LyrebirdRandom(seed: 42)
/// let freq: Double = r.exponentialRange(low: 200, high: 2000) // Hz, log-uniform
/// let dur: Double = r.uniform(low: 0.1, high: 0.5) // seconds
/// let jitter: Double = r.gauss(mean: 0, dev: 0.02) // ± around 0
/// ```
///
/// Each draw method maps to a ``DistributionKind`` case; the generic
/// ``value(_:parX:parY:parA:parB:)`` reaches any distribution by kind. For
/// throwaway draws with no seed bookkeeping, use ``shared``.
///
/// Value semantics: copying a `LyrebirdRandom` forks its stream. Not
/// thread-safe — give each thread its own instance (or use ``shared``, which is
/// synchronized).
public struct LyrebirdRandom: Sendable {
/// The live xorshift64 state. Exposed so callers can snapshot/restore a
/// draw position; mutated by every draw.
public var state: UInt64
/// Create a reproducible source from an explicit seed.
/// - Parameter seed: Any `UInt64`; normalised to a non-zero xorshift state.
public init(seed: UInt64) {
self.state = lyrebirdSeedXorshift64(from: seed)
}
/// Create a source seeded from system entropy (uptime nanoseconds) — draws
/// are not reproducible across runs. Prefer ``init(seed:)`` when you need
/// repeatability.
public init() {
self.state = lyrebirdSeedXorshift64(from: nil)
}
// MARK: - Generic
/// Draw one sample from `kind`, advancing this source's state.
/// - Parameters:
/// - kind: The distribution to sample.
/// - parX: First parameter (per ``DistributionKind``'s table).
/// - parY: Second parameter. Ignored by single-parameter distributions.
/// - parA: Third parameter (beta `alpha` / Cauchy positive-only). `nil` = default.
/// - parB: Fourth parameter (beta `beta`). `nil` = default.
/// - Returns: One sample.
public mutating func value(
_ kind: DistributionKind,
parX: Double,
parY: Double = 1,
parA: Double? = nil,
parB: Double? = nil
) -> Double {
kind.sample(parX: parX, parY: parY, parA: parA, parB: parB, using: &state)
}
// MARK: - Uniform family
/// A uniform sample in `[0, 1]`.
public mutating func unit() -> Double {
DistributionKind.uniform.sample(parX: 0, parY: 1, using: &state)
}
/// Uniform (flat) sample in `[low, high]`.
public mutating func uniform(low: Double, high: Double) -> Double {
DistributionKind.uniform.sample(parX: low, parY: high, using: &state)
}
/// Sample in `[low, high]` biased toward `low` (squared uniform).
public mutating func lowBiased(low: Double, high: Double) -> Double {
DistributionKind.lpRand.sample(parX: low, parY: high, using: &state)
}
/// Sample in `[low, high]` biased toward `high` (mirrored squared uniform).
public mutating func highBiased(low: Double, high: Double) -> Double {
DistributionKind.hpRand.sample(parX: low, parY: high, using: &state)
}
/// Sample in `[low, high]` biased toward the midpoint (mean of two uniforms).
public mutating func meanBiased(low: Double, high: Double) -> Double {
DistributionKind.meanRand.sample(parX: low, parY: high, using: &state)
}
/// Log-uniform sample in `[low, high]`; both bounds must be `> 0`.
public mutating func exponentialRange(low: Double, high: Double) -> Double {
DistributionKind.expRand.sample(parX: low, parY: high, using: &state)
}
// MARK: - Single-parameter families
/// Standard exponential; `density` is the rate λ (`> 0`). Output `≥ 0`.
public mutating func exponential(density: Double) -> Double {
DistributionKind.exponential.sample(parX: density, using: &state)
}
/// Gamma distribution; `shape` is `k` (`> 0`). `k = 1` is exponential.
public mutating func gamma(shape: Double) -> Double {
DistributionKind.gamma.sample(parX: shape, using: &state)
}
/// Laplace (double-exponential), symmetric about 0; `scale` is dispersion `b`.
public mutating func laplace(scale: Double = 1) -> Double {
DistributionKind.laplace.sample(parX: scale, using: &state)
}
/// Asymmetric Laplace (right tail heavier, p = 0.7); `scale` is dispersion `b`.
public mutating func asymmetricLaplace(scale: Double = 1) -> Double {
DistributionKind.alaplace.sample(parX: scale, using: &state)
}
/// Half-cosine bell centred at 0; output ≈ `[−d/π, d/π]`.
public mutating func halfCosine(dispersion: Double = 1) -> Double {
DistributionKind.hcos.sample(parX: dispersion, using: &state)
}
/// Logistic distribution centred at 0 (heavier tails than Gaussian); `scale` is `s`.
public mutating func logistic(scale: Double = 1) -> Double {
DistributionKind.logistic.sample(parX: scale, using: &state)
}
/// Poisson counts; `mean` is λ (clamped to `[0.001, 30]`). Integer-valued.
public mutating func poisson(mean: Double) -> Double {
DistributionKind.poisson.sample(parX: mean, using: &state)
}
/// U-shaped arcsin distribution; output in `[−dispersion, dispersion]`.
public mutating func arcsin(dispersion: Double = 1) -> Double {
DistributionKind.arcsin.sample(parX: dispersion, using: &state)
}
// MARK: - Multi-parameter families
/// Beta distribution mapped to `[low, high]`. `alpha`/`beta` shape it
/// (`alpha == beta` symmetric; both `< 1` bimodal; `1, 1` uniform).
public mutating func beta(
low: Double,
high: Double,
alpha: Double = 2,
beta: Double = 2
) -> Double {
DistributionKind.betaRand.sample(parX: low, parY: high, parA: alpha, parB: beta, using: &state)
}
/// Cauchy distribution; heavy-tailed. `positiveOnly` folds onto the positive axis.
public mutating func cauchy(
mean: Double = 0,
spread: Double = 1,
positiveOnly: Bool = false
) -> Double {
DistributionKind.cauchy.sample(parX: mean, parY: spread, parA: positiveOnly ? 1 : 0, using: &state)
}
/// Gaussian (normal) distribution; `dev` is the standard deviation σ.
public mutating func gauss(mean: Double = 0, dev: Double = 1) -> Double {
DistributionKind.gauss.sample(parX: dev, parY: mean, using: &state)
}
}
@@ -0,0 +1,138 @@
// SharedRandom.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Foundation
/// Process-wide, thread-safe scalar random source for throwaway draws where you
/// don't want to thread a ``LyrebirdRandom`` through your code. Reached via
/// ``LyrebirdRandom/shared``.
///
/// ```swift
/// let x: Double = LyrebirdRandom.shared.uniform(low: 0, high: 1)
/// let g: Double = LyrebirdRandom.shared.gauss(mean: 0, dev: 1)
/// ```
///
/// System-seeded, so its stream is **not reproducible** across runs, and its
/// interleaving across threads is non-deterministic — every draw locks a shared
/// state. When you need repeatable draws (e.g. a rendered score), use an owned
/// `LyrebirdRandom(seed:)` instead. Call ``reseed(_:)`` to pin the shared stream
/// for a test.
public final class SharedRandom: @unchecked Sendable {
private var gen: LyrebirdRandom
private let lock: NSLock = NSLock()
init() {
self.gen = LyrebirdRandom()
}
/// Replace the shared state with one seeded from `seed`. Mainly for tests
/// that need the shared source to be reproducible.
public func reseed(_ seed: UInt64) {
lock.lock(); defer { lock.unlock() }
gen = LyrebirdRandom(seed: seed)
}
private func locked(_ body: (inout LyrebirdRandom) -> Double) -> Double {
lock.lock(); defer { lock.unlock() }
return body(&gen)
}
/// See ``LyrebirdRandom/value(_:parX:parY:parA:parB:)``.
public func value(
_ kind: DistributionKind,
parX: Double,
parY: Double = 1,
parA: Double? = nil,
parB: Double? = nil
) -> Double {
locked { $0.value(kind, parX: parX, parY: parY, parA: parA, parB: parB) }
}
/// See ``LyrebirdRandom/unit()``.
public func unit() -> Double { locked { $0.unit() } }
/// See ``LyrebirdRandom/uniform(low:high:)``.
public func uniform(low: Double, high: Double) -> Double { locked { $0.uniform(low: low, high: high) } }
/// See ``LyrebirdRandom/lowBiased(low:high:)``.
public func lowBiased(low: Double, high: Double) -> Double { locked { $0.lowBiased(low: low, high: high) } }
/// See ``LyrebirdRandom/highBiased(low:high:)``.
public func highBiased(low: Double, high: Double) -> Double { locked { $0.highBiased(low: low, high: high) } }
/// See ``LyrebirdRandom/meanBiased(low:high:)``.
public func meanBiased(low: Double, high: Double) -> Double { locked { $0.meanBiased(low: low, high: high) } }
/// See ``LyrebirdRandom/exponentialRange(low:high:)``.
public func exponentialRange(low: Double, high: Double) -> Double { locked { $0.exponentialRange(low: low, high: high) } }
/// See ``LyrebirdRandom/exponential(density:)``.
public func exponential(density: Double) -> Double { locked { $0.exponential(density: density) } }
/// See ``LyrebirdRandom/gamma(shape:)``.
public func gamma(shape: Double) -> Double { locked { $0.gamma(shape: shape) } }
/// See ``LyrebirdRandom/laplace(scale:)``.
public func laplace(scale: Double = 1) -> Double { locked { $0.laplace(scale: scale) } }
/// See ``LyrebirdRandom/asymmetricLaplace(scale:)``.
public func asymmetricLaplace(scale: Double = 1) -> Double { locked { $0.asymmetricLaplace(scale: scale) } }
/// See ``LyrebirdRandom/halfCosine(dispersion:)``.
public func halfCosine(dispersion: Double = 1) -> Double { locked { $0.halfCosine(dispersion: dispersion) } }
/// See ``LyrebirdRandom/logistic(scale:)``.
public func logistic(scale: Double = 1) -> Double { locked { $0.logistic(scale: scale) } }
/// See ``LyrebirdRandom/poisson(mean:)``.
public func poisson(mean: Double) -> Double { locked { $0.poisson(mean: mean) } }
/// See ``LyrebirdRandom/arcsin(dispersion:)``.
public func arcsin(dispersion: Double = 1) -> Double { locked { $0.arcsin(dispersion: dispersion) } }
/// See ``LyrebirdRandom/beta(low:high:alpha:beta:)``.
public func beta(
low: Double,
high: Double,
alpha: Double = 2,
beta: Double = 2
) -> Double {
locked { $0.beta(low: low, high: high, alpha: alpha, beta: beta) }
}
/// See ``LyrebirdRandom/cauchy(mean:spread:positiveOnly:)``.
public func cauchy(
mean: Double = 0,
spread: Double = 1,
positiveOnly: Bool = false
) -> Double {
locked { $0.cauchy(mean: mean, spread: spread, positiveOnly: positiveOnly) }
}
/// See ``LyrebirdRandom/gauss(mean:dev:)``.
public func gauss(mean: Double = 0, dev: Double = 1) -> Double {
locked { $0.gauss(mean: mean, dev: dev) }
}
}
extension LyrebirdRandom {
/// Process-wide thread-safe source for quick, non-reproducible draws.
/// See ``SharedRandom``.
public static let shared: SharedRandom = SharedRandom()
}
/// Global shorthand for the process-wide shared random source
/// (``LyrebirdRandom/shared``) — the common non-seeded case.
///
/// ```swift
/// let pan: Double = Random.uniform(low: -1, high: 1)
/// let freq: Double = Random.exponentialRange(low: 200, high: 2000)
/// ```
///
/// Draws are **not reproducible** across runs; for a repeatable seeded stream use
/// `LyrebirdRandom(seed:)`. Capitalized to avoid shadowing C's `rand()`.
public let Random: SharedRandom = LyrebirdRandom.shared
@@ -73,8 +73,8 @@ public final class DemandTemporalTendency: TimedDemandGenerator {
/// - distribution: Distribution family to sample from.
/// - parX: First parameter (lo, density, mode, dev, dispersion — see `DistributionKind`).
/// - parY: Second parameter (hi for two-parameter distributions; default `.value(1.0)`).
/// - parA: Third parameter (alpha/lowProb for betaRand; posOnly flag for cauchy). `nil` = use distribution default.
/// - parB: Fourth parameter (beta/highProb for betaRand). `nil` = use distribution default.
/// - parA: Third parameter (alpha for betaRand; posOnly flag for cauchy). `nil` = use distribution default.
/// - parB: Fourth parameter (beta for betaRand). `nil` = use distribution default.
/// - repeats: Number of pulls before exhaustion. `-1` = infinite.
/// - seed: PRNG seed. Defaults to a time-derived value.
public init(
@@ -126,42 +126,6 @@ public final class DemandTemporalTendency: TimedDemandGenerator {
a: Double?,
b: Double?
) -> Double {
switch _distribution {
case .uniform:
return _sampleUniform(lo: x, hi: y, rng: &_rng)
case .lpRand:
return _sampleLpRand(lo: x, hi: y, rng: &_rng)
case .hpRand:
return _sampleHpRand(lo: x, hi: y, rng: &_rng)
case .meanRand:
return _sampleMeanRand(lo: x, hi: y, rng: &_rng)
case .expRand:
return _sampleExpRand(lo: x, hi: y, rng: &_rng)
case .exponential:
return _sampleExponential(density: x, rng: &_rng)
case .gamma:
return _sampleGamma(shape: x, rng: &_rng)
case .laplace:
return _sampleLaplace(dispersion: x, rng: &_rng)
case .alaplace:
return _sampleALaplace(dispersion: x, rng: &_rng)
case .hcos:
return _sampleHcos(dispersion: x, rng: &_rng)
case .logistic:
return _sampleLogistic(dispersion: x, rng: &_rng)
case .poisson:
return _samplePoisson(mean: x, rng: &_rng)
case .arcsin:
return _sampleArcsin(dispersion: x, rng: &_rng)
case .betaRand:
let alpha: Double = a ?? 2.0
let beta: Double = b ?? 2.0
return _sampleBetaRand(lo: x, hi: y, alpha: alpha, beta: beta, rng: &_rng)
case .cauchy:
let posOnly: Bool = (a ?? 0) > 0
return _sampleCauchy(mean: x, spread: y, posOnly: posOnly, rng: &_rng)
case .gauss:
return _sampleGauss(dev: x, mean: y, rng: &_rng)
}
_distribution.sample(parX: x, parY: y, parA: a, parB: b, using: &_rng)
}
}
@@ -82,6 +82,52 @@ The same helpers work inside RT `_computeSamples` bodies (no allocation, no lock
`rngState: UInt64` on the Generator and pass `&rngState` per call. Generators in the noise
family inherit this state via ``NoiseBase``.
### Distribution-shaped scalars — ``LyrebirdRandom``
The stdlib and xorshift helpers above give you a *uniform* scalar. When you want a single draw
from a *specific distribution* — Gaussian jitter, an exponential (log-uniform) frequency, a
Laplace-shaped deviation, a Beta-weighted position — use ``LyrebirdRandom``. It owns a
xorshift64 state, so a given `seed` produces a fully reproducible stream of draws, and it
covers every family in ``DistributionKind``:
```swift
var r = LyrebirdRandom(seed: 42)
let freq: Double = r.exponentialRange(low: 200, high: 2000) // Hz, log-uniform
let dur: Double = r.uniform(low: 0.1, high: 0.5) // seconds
let jitter: Double = r.gauss(mean: 0, dev: 0.02) // ± around 0
let skew: Double = r.beta(low: 0, high: 1, alpha: 2, beta: 5)
let spike: Double = r.laplace(scale: 1.0)
```
Named methods exist for the common families (``LyrebirdRandom/uniform(low:high:)``,
``LyrebirdRandom/gauss(mean:dev:)``, ``LyrebirdRandom/laplace(scale:)``,
``LyrebirdRandom/exponentialRange(low:high:)``, ``LyrebirdRandom/cauchy(mean:spread:positiveOnly:)``,
``LyrebirdRandom/beta(low:high:alpha:beta:)`` …); reach any distribution by kind with
``LyrebirdRandom/value(_:parX:parY:parA:parB:)``.
For throwaway draws where you don't want to thread a source through your code, use the
process-wide, thread-safe ``LyrebirdRandom/shared`` (system-seeded, **not** reproducible).
The global ``Random`` is a shorthand for exactly that shared instance — the common
non-seeded case:
```swift
let x: Double = Random.uniform(low: 0, high: 1) // == LyrebirdRandom.shared
let g: Double = Random.gauss(mean: 0, dev: 1)
let f: Double = Random.exponentialRange(low: 200, high: 2000)
```
The single-draw dispatch (``DistributionKind/sample(parX:parY:parA:parB:using:)``) is the same
mapping ``TemporalTendency`` and ``DemandTemporalTendency`` use — so a scalar draw and a stream
of the same distribution agree given the same seed. `LyrebirdRandom` is not thread-safe (give
each thread its own instance); `shared` is synchronized.
> Warning: ``SharedRandom`` / ``Random`` take a **lock** on every draw, so they are **not
> RT-safe** — never call `Random.…` (or `LyrebirdRandom.shared.…`) from a Generator's
> `_computeSamples` or any audio-thread path. Inside a Generator, store an owned
> ``LyrebirdRandom`` (seeded at `init`) and draw from it: it holds no lock, is pure arithmetic,
> and is RT-safe. `Random` is for non-RT setup / language-side code (Synthesizer `init`,
> demos, live-coding snippets, tests).
### Want a *signal*, not a scalar?
For random *signals* — control-rate values that re-fire on a trigger, smoothed random walks,
@@ -197,6 +243,10 @@ default or to temporarily freeze jitter without removing the generator.
## See Also
- ``LyrebirdRandom``
- ``SharedRandom``
- ``Random``
- ``DistributionKind``
- <doc:Noise>
- <doc:TemporalDemand>
- ``Impulse``
@@ -36,7 +36,7 @@ Pick a scheme from the toolbar and hit **Run**:
| `LyrebirdiOSDemo` | SwiftUI app — same UI via `iOSAudioDriver` (RemoteIO) | iOS |
| `LyrebirdNRTDemo` | CLI — renders to `~/Desktop/nrt_output.caf` and exits | macOS |
| `LyrebirdAUv3Demo` | AUv3 host app + `aumu` plugin extension (`Realized Sound: LyrebirdFM`) — a two-operator FM synth wrapped as ``LyrebirdAudioUnit``, loadable in Logic, GarageBand, AUM, Loopy Pro, etc. Run the host app once to register the extension, then load the plugin in any AUv3-capable host. | macOS |
| `LyrebirdScratchDemo` | Live-coding scratchpad — compile a Swift snippet at ⌘↩, `dlopen` the dylib, run it against the live engine. ⌘⇧↩ is additive (prior synths stay). | macOS |
| `LyrebirdScratch` | Live-coding scratchpad — compile a Swift snippet at ⌘↩, `dlopen` the dylib, run it against the live engine. ⌘⇧↩ is additive (prior synths stay). | macOS |
Use `Lyrebird-Package` for day-to-day development of the engine and tests. The other entries are convenience runs for the specific module or demo you're iterating on.
+1 -1
View File
@@ -39,7 +39,7 @@ try engine.add(MySynth()) // MySynth — your SynthesizerBase subclass
- <doc:Oscillators>
- <doc:Noise>
- <doc:Random>
- <doc:RandomAndJitter>
### Buffer Utilities
@@ -481,5 +481,5 @@ Pass `timespan: 0` to snapshot all values at `elapsedSeconds = 0`. Pass a non-ze
- ``TemporalParameter``
- ``DistributionKind``
- <doc:Noise>
- <doc:Random>
- <doc:RandomAndJitter>
- <doc:RoutineTask>
@@ -118,45 +118,6 @@ public final class TemporalTendency: TemporalAlgorithmBase {
b: Double?,
rng: inout UInt64
) -> Double {
let betaDefaultAlpha: Double = 2.0
let betaDefaultBeta: Double = 2.0
switch _distribution {
case .uniform:
return _sampleUniform(lo: x, hi: y, rng: &rng)
case .lpRand:
return _sampleLpRand(lo: x, hi: y, rng: &rng)
case .hpRand:
return _sampleHpRand(lo: x, hi: y, rng: &rng)
case .meanRand:
return _sampleMeanRand(lo: x, hi: y, rng: &rng)
case .expRand:
return _sampleExpRand(lo: x, hi: y, rng: &rng)
case .exponential:
return _sampleExponential(density: x, rng: &rng)
case .gamma:
return _sampleGamma(shape: x, rng: &rng)
case .laplace:
return _sampleLaplace(dispersion: x, rng: &rng)
case .alaplace:
return _sampleALaplace(dispersion: x, rng: &rng)
case .hcos:
return _sampleHcos(dispersion: x, rng: &rng)
case .logistic:
return _sampleLogistic(dispersion: x, rng: &rng)
case .poisson:
return _samplePoisson(mean: x, rng: &rng)
case .arcsin:
return _sampleArcsin(dispersion: x, rng: &rng)
case .betaRand:
return _sampleBetaRand(
lo: x, hi: y,
alpha: a ?? betaDefaultAlpha,
beta: b ?? betaDefaultBeta,
rng: &rng)
case .cauchy:
return _sampleCauchy(mean: x, spread: y, posOnly: (a ?? 0) > 0, rng: &rng)
case .gauss:
return _sampleGauss(dev: x, mean: y, rng: &rng)
}
_distribution.sample(parX: x, parY: y, parA: a, parB: b, using: &rng)
}
}