./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
14 / 14
100.0%
Branches:
2 / 2
100.0%
Functions:
3 / 3
100.0%

src/random/stream.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 #include "terraingen/random/stream.h"
4
5 namespace terraingen {
6
7 40490364 RandomStream::RandomStream(std::uint32_t seed, std::uint32_t stream, std::uint32_t a,
8 40490364 std::uint32_t b, std::uint32_t c)
9 40490364 : m_key{seed, stream}, m_counter{a, b, c, 0u} {}
10
11 775734398 std::uint32_t RandomStream::NextU32() {
12
2/2
✓ Branch 0 taken 203757397 times.
✓ Branch 1 taken 571977001 times.
775734398 if (m_used == 4) {
13 203757397 m_block = Philox4x32(m_counter, m_key);
14 203757397 ++m_counter.w;
15 203757397 m_used = 0;
16 }
17 775734398 const std::uint32_t words[4] = {m_block.x, m_block.y, m_block.z, m_block.w};
18 775734398 return words[m_used++];
19 }
20
21 371945856 double RandomStream::NextDouble() {
22 371945856 const std::uint64_t high = NextU32() >> 5u;
23 371984443 const std::uint64_t low = NextU32() >> 6u;
24 372005049 return static_cast<double>((high << 26u) | low) * 0x1p-53;
25 }
26
27 } // namespace terraingen
28