Skip to content

Commit 4b3a3de

Browse files
committed
Add ranqd1 from Numerical Recipes in C, 2nd Edition.
1 parent 624ad36 commit 4b3a3de

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

internals/testing/ranqd1_test.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "dumpster_v1/ranqd1.hpp"
2+
3+
#include "testing_v1/test.hpp"
4+
5+
using namespace testing_v1;
6+
using namespace dumpster_v1;
7+
8+
auto ranqd1_test = test([]() {
9+
uint32_t seed = 0;
10+
verify((seed = ranqd1(seed)) == 0x3c6ef35f);
11+
verify((seed = ranqd1(seed)) == 0x47502932);
12+
verify((seed = ranqd1(seed)) == 0xd1ccf6e9);
13+
verify((seed = ranqd1(seed)) == 0xaaf95334);
14+
verify((seed = ranqd1(seed)) == 0x6252e503);
15+
verify((seed = ranqd1(seed)) == 0x9f2ec686);
16+
verify((seed = ranqd1(seed)) == 0x57fe6c2d);
17+
verify((seed = ranqd1(seed)) == 0xa3d95fa8);
18+
verify((seed = ranqd1(seed)) == 0x81fdbee7);
19+
verify((seed = ranqd1(seed)) == 0x94f0af1a);
20+
verify((seed = ranqd1(seed)) == 0xcbf633b1);
21+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#include "dumpster_v1/synopsis.hpp"
4+
5+
inline uint32_t dumpster_v1::ranqd1(uint32_t seed) {
6+
return seed * 1664525 + 1013904223;
7+
}

provides/include/dumpster_v1/synopsis.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <cstdint>
4+
35
#include "dumpster_v1/private.hpp"
46

57
namespace dumpster_v1 {
@@ -53,6 +55,11 @@ template <class Action> struct finally_t : Private::finally_t<Action> {
5355
template <class Action>
5456
finally_t<std::remove_cvref_t<Action>> finally(Action &&action);
5557

58+
// ranqd1.hpp ==================================================================
59+
60+
/// The `ranqd1` generator from Numerical Recipes in C, 2nd Edition.
61+
uint32_t ranqd1(uint32_t seed);
62+
5663
// insertion_sort.hpp ==========================================================
5764

5865
/// Sorts given sentinel terminated sequence to ascending order. Intended for

0 commit comments

Comments
 (0)