Skip to content

Parallel streams, frozen floating-point derivations

Latest

Choose a tag to compare

@nate-sentjens nate-sentjens released this 18 Aug 23:57
4d253bc

Purely additive release & no breaking changes. All existing frozen operations and golden vectors are unchanged.

Parallel streams

New jump-based stream derivation for reproducible parallel workloads. stream(seed:index:) creates provably non-overlapping generators keyed to a logical index, for bitwise-reproducible results under any execution order.

await withTaskGroup(of: (Int, Double).self) { group in
    for i in 0..<taskCount {
        group.addTask {
            var rng = SeededRandom.stream(seed: seed, index: i)
            let result = runSimulation(using: &rng)

            return (i, result)
        }
    }
}

Each stream is separated by 2¹²⁸ steps.

Frozen floating-point derivations

  • nextUniformDouble() — 53-bit uniform [0, 1) conversion using only integer shift and one IEEE-754-exact multiply.
  • nextBernoulli(_:) — returns true with the given probability, consuming exactly one raw draw regardless of outcome.

These complete the frozen derivation chain from raw bits through floating-point values without ever calling a transcendental function (log, cos, exp), preserving swift-seeded-random's absolute cross-platform stability guarantee.

All additions

  • Xoshiro256StarStar: jump(), longJump(), jumped(by:), longJumped(), stream(seed:index:) — Blackman-Vigna reference polynomials
  • SeededRandom: forwards all jump and stream operations
  • SplitMix64: advanced(by:) — O(1) closed-form state advance
  • StableRandomSource: nextUniformDouble(), nextBernoulli(_:)
  • Golden vector tests for every new operation
  • DocC articles: Parallel Streams, Floating-Point Derivations
  • C reference harness under Tests/Fixtures/reference/