Skip to content

Instantly share code, notes, and snippets.

@odanado
Created December 6, 2016 03:43
Show Gist options
  • Save odanado/94c011ca482b46bb6cbe8e2e815066ce to your computer and use it in GitHub Desktop.
Save odanado/94c011ca482b46bb6cbe8e2e815066ce to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <array>
#include "tinymt32.h"
using Status = std::array<uint32_t, 4>;
std::array<Status, 4> seeds = {
Status{0x63B07A71, 0x5740A11A, 0x3CFE1DE3, 0x08A80987},
Status{0x5740A11A, 0x3CFE1DE3, 0xA5083B98, 0x14EF46DC},
Status{0x3CFE1DE3, 0x2A782A76, 0xA21332BC, 0x4D436C11},
Status{0x2A782A76, 0xA21332BC, 0xAAEA877B, 0xB65DD562}};
void setStatus(tinymt32_t* random, int idx) {
for (int i = 0; i < 4; i++) {
random->status[i] = seeds[idx][i];
}
}
void print_hex(uint32_t i) { printf("%08X ", i); }
int main() {
tinymt32_t random;
random.mat1 = 0x8F7011EE;
random.mat2 = 0xFC78FF1F;
random.tmat = 0x3793fdff;
setStatus(&random, 0);
for (int i = 0; i < 1000; i++) {
/*
for (int j = 3; j >= 0; j--) {
print_hex(random.status[j]);
// print_hex(random.status[j] ^ seeds[i][j]);
}
*/
// 実際に使われる乱数
auto r = tinymt32_temper(&random);
if (r == 0x17D1738B) {
printf("%d\n", i);
print_hex(r);
printf("\n");
}
tinymt32_next_state(&random);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment