diff options
| author | Benedict <benedict@0xb8000.de> | 2016-08-13 00:56:06 +0200 |
|---|---|---|
| committer | Benedict <benedict@0xb8000.de> | 2017-02-21 13:00:25 +0100 |
| commit | f48cae2dcd5ff60c678484cd213881cc90722d41 (patch) | |
| tree | 9a63789c89dc0a6494950ee2cab7054ca8c7f960 /set3 | |
| parent | b2aa636bfee0c4a7f607eaad06803cd7c42d8214 (diff) | |
set3, completed task 23
Diffstat (limited to 'set3')
| -rw-r--r-- | set3/task21.c | 5 | ||||
| -rw-r--r-- | set3/task23.c | 41 |
2 files changed, 44 insertions, 2 deletions
diff --git a/set3/task21.c b/set3/task21.c index e8a48d1..ac19a1e 100644 --- a/set3/task21.c +++ b/set3/task21.c @@ -6,9 +6,10 @@ #define BLOCKSIZE 16 int main() { + struct mt_19937_state mt_state; unsigned int seed = 111; int i; - mt_19937_seed(seed); + mt_19937_seed(seed, &mt_state); for(i=0;i<10;i++) - printf("%u\n", mt_19937()); + printf("%u\n", mt_19937(&mt_state)); } diff --git a/set3/task23.c b/set3/task23.c new file mode 100644 index 0000000..7987e2a --- /dev/null +++ b/set3/task23.c @@ -0,0 +1,41 @@ +#include "../lib/lib.h" +#include "../lib/lib2.h" +#include "../lib/lib3.h" +#include <time.h> + +int main() +{ + struct mt_19937_state mt_state; + struct mt_19937_state mt_state2; + mt_state2.index = 624; + mt_19937_seed(time(NULL), &mt_state); + unsigned int val[624]; + int i; + // obtaining 624 values + + for(i=0;i<624;i++) + val[i] = mt_19937(&mt_state); + + unsigned int tmp; + unsigned int tmp2; + // restore the state + for(i=0;i<624;i++) { + tmp = unshift_right_xor(val[i], 18); + tmp = unshift_left_xor(tmp, 15, 0xEFC60000); + tmp = unshift_left_xor(tmp, 7, 0x9D2C5680); + mt_state2.mt[i] = unshift_right_xor(tmp, 11); + if (mt_state2.mt[i] != mt_state.mt[i]) + printf("state %i not euql\n", i); + } + + // check if the next numbers are the same for both MT PRNG + + for(i=0;i<624;i++) { + tmp = mt_19937(&mt_state); + tmp2 = mt_19937(&mt_state2); + if (tmp != tmp2) { + printf("NOT EQUAL, CHECK YOUR DAMM CODE\n"); + break; + } + } +} |
