2 * Simple random number generator for testing.
3 * Copyright © 2022-2023 Nick Bowler
5 * Directly compare the test lib RNG against the reference implementation.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
29 unsigned long long seed_state = 0xdeadbeeff00dcafe;
30 unsigned long long test_result, ref_result;
31 unsigned long long ref_state[4], test_state[4];
35 for (i = 0; i < 100; i++) {
36 s[0] = ref_state[0] = test_state[0] = splitmix64(&seed_state);
37 s[1] = ref_state[1] = test_state[1] = splitmix64(&seed_state);
38 s[2] = ref_state[2] = test_state[2] = splitmix64(&seed_state);
39 s[3] = ref_state[3] = test_state[3] = splitmix64(&seed_state);
42 test_result = xoshiro256p(test_state);
44 if (!tap_result(ref_result == test_result, "rng output")) {
45 tap_diag("Failed, unexpected result");
46 tap_diag(" with initial state %llx %llx %llx %llx",
47 ref_state[0], ref_state[1],
48 ref_state[2], ref_state[3]);
49 tap_diag(" received: %llx", test_result);
50 tap_diag(" expected: %llx", ref_result);
53 if (!tap_result(s[0] == test_state[0] && s[1] == test_state[1]
54 && s[2] == test_state[2] && s[3] == test_state[3],
57 tap_diag("Failed, state update differed");
58 tap_diag(" with initial state %llx %llx %llx %llx",
59 ref_state[0], ref_state[1],
60 ref_state[2], ref_state[3]);
61 tap_diag(" received: %llx %llx %llx %llx",
62 test_state[0], test_state[1],
63 test_state[2], test_state[3]);
64 tap_diag(" expected: %llx %llx %llx %llx",
65 (unsigned long long)s[0],
66 (unsigned long long)s[1],
67 (unsigned long long)s[2],
68 (unsigned long long)s[3]);