Files
Lyrebird/Sources/Lyrebird/Patterns/Engines/RandomPatternBase.swift
T

20 lines
719 B
Swift

// RandomPatternBase.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
/// Shared base for pattern engines that own a persistent xorshift64 PRNG state.
///
/// Subclasses inherit `_rngState` and call `super.init(seed:)` to seed it via
/// `lyrebirdSeedXorshift64(from:)`. `reset()` intentionally does not reseed —
/// mirrors the `DemandRandom` convention so retriggering avoids audible repetition.
internal class _RandomPatternBase {
/// xorshift64 PRNG state. Subclasses read and advance this via `xorshift64NextRaw`.
internal var _rngState: UInt64
internal init(seed: UInt64?) {
_rngState = lyrebirdSeedXorshift64(from: seed)
}
}