summaryrefslogtreecommitdiff
path: root/source/test/unittests/mersenne_twister_64.test.c
blob: 37c82b4bb332b3ef43deb25364610a2d14e85268 (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
#include "../../kit/mersenne_twister_64.h"

#define TEST_FILE mersenne_twister_64
#include "../../kit_test/test.h"

enum { SIZE = 1000 };

TEST("mt64 same seeds") {
  uint64_t seed = mt64_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);
}