summaryrefslogtreecommitdiff
path: root/source/tests/mersenne_twister_64.test.c
blob: a138a4151d221fd9a748879648f8c87ad714302c (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
36
37
38
#include "../kit/mersenne_twister_64.h"
#include "../kit/secure_random.h"

#define KIT_TEST_FILE mersenne_twister_64
#include "../kit/kit_test.h"

enum { MT64_TEST_SIZE = 1000 };

TEST("mt64 same seeds") {
  ptrdiff_t i;
  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 (i = 0; i < MT64_TEST_SIZE; i++)
    ok = ok && mt64_generate(&foo) == mt64_generate(&bar);

  REQUIRE(ok);
}

TEST("mt64 different seeds") {
  ptrdiff_t i;

  mt64_state_t foo, bar;
  mt64_init(&foo, 42);
  mt64_init(&bar, 4242424242);

  ptrdiff_t difference_count = 0;
  for (i = 0; i < MT64_TEST_SIZE; i++)
    if (mt64_generate(&foo) != mt64_generate(&bar))
      difference_count++;

  REQUIRE(difference_count > MT64_TEST_SIZE / 2);
}