Files
Lyrebird/Sources/Lyrebird/Generators/Demand/DemandUniformRandom.swift
T
2026-06-01 18:27:40 -07:00

46 lines
1.5 KiB
Swift

// DemandUniformRandom.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
/// Demand-rate uniform random samples in `[low, high]`.
///
/// RT-side counterpart to ``Pattern/uniformRandom(low:high:length:seed:)``.
/// Backed by the same module-internal ``UniformRandomPatternEngine``.
/// Complement to the pool-based ``DemandRandom``: this draws continuous
/// values inside a range rather than picking from a discrete set.
///
/// **RT contract** — xorshift64 PRNG, no allocation, no locks. Single-owner
/// per puller. `reset()` rewinds the response counter but intentionally does
/// NOT restore the PRNG seed (mirrors `DemandRandom` precedent).
public final class DemandUniformRandom: DemandGenerator {
private let _engine: UniformRandomPatternEngine
/// - Parameters:
/// - low: Lower bound (inclusive).
/// - high: Upper bound (inclusive).
/// - length: Total responses before exhaustion. `-1` = infinite.
/// - seed: PRNG seed. `nil` = time-derived.
public init(
low: Double,
high: Double,
length: Int = -1,
seed: UInt64? = nil
) {
_engine = UniformRandomPatternEngine(
low: low,
high: high,
length: length,
seed: seed
)
}
public var isExhausted: Bool { _engine.isExhausted }
public func nextValue() -> Double? { _engine.next() }
public func reset() { _engine.reset() }
}