blob: 80d1c2c287a2ff576adfb8be46688c78c3cfdaf1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include "../../kit/mersenne_twister_64.h"
#include "../../kit/secure_random.h"
#define KIT_TEST_FILE mersenne_twister_64
#include "../../kit_test/test.h"
enum { SIZE = 1000 };
TEST("mt64 same seeds") {
uint64_t seed;
secure_random(sizeof seed, &seed);
mt64_state_t foo, bar;
mt64_init(&foo, seed);
mt64_init(&bar, seed);
int ok = 1;
for (ptrdiff_t i = 0; i < SIZE; i++)
ok = ok && mt64_generate(&foo) == mt64_generate(&bar);
REQUIRE(ok);
}
TEST("mt64 different seeds") {
mt64_state_t foo, bar;
mt64_init(&foo, 42);
mt64_init(&bar, 4242424242);
ptrdiff_t difference_count = 0;
for (ptrdiff_t i = 0; i < SIZE; i++)
if (mt64_generate(&foo) != mt64_generate(&bar))
difference_count++;
REQUIRE(difference_count > SIZE / 2);
}
|