Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // randomNumberGenerators.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <chrono>
- #include <iostream>
- #include <iomanip>
- #include <random>
- #include "random.h"
- int main()
- {
- uint64_t seed64 = std::chrono::system_clock::now().time_since_epoch().count();
- std::mt19937_64 generator(seed64);
- // Scenario #1 - LCG seeded from LCG gives same results
- uint32_t seed32 = uint32_t(generator() & 0xFFFFFFFF);
- std::cout << "LCG#1 created with seed " << std::setw(10) << seed32 << std::endl;
- auto lcg1 = new LCG(seed32);
- seed32 = (*lcg1)();
- std::cout << "LCG#2 created with seed " << std::setw(10) << seed32 << std::endl;
- auto lcg2 = new LCG(seed32);
- for (size_t i = 0; i < 16; ++i) {
- std::cout << std::setw(10) << (*lcg1)() << ", " << std::setw(10) << (*lcg2)() << std::endl;
- }
- std::cout << std::endl;
- // Scenario #2 - PSEUDO_DES seeded from monotonically increasing seeds (correlated)
- seed64 = generator();
- uint32_t hi = uint32_t(seed64 >> 32);
- uint32_t lo = uint32_t(seed64 & 0xFFFFFFFF);
- std::cout << "PDES#1 created with seed " << std::setw(10) << hi << '-' << std::setw(10) << lo << std::endl;
- auto pdes1 = new PSEUDO_DES(hi, lo);
- seed64 += 1;
- hi = uint32_t(seed64 >> 32);
- lo = uint32_t(seed64 & 0xFFFFFFFF);
- std::cout << "PDES#2 created with seed " << std::setw(10) << hi << '-' << std::setw(10) << lo << std::endl;
- auto pdes2 = new PSEUDO_DES(hi, lo);
- for (size_t i = 0; i < 16; ++i) {
- std::cout << std::setw(10) << (*pdes1)() << ", " << std::setw(10) << (*pdes2)() << std::endl;
- }
- std::cout << std::endl;
- // Scenario #3 - AES_COUNTER seeded from monotonically increasing seeds (not obviously correlated)
- seed64 = generator();
- hi = uint32_t(seed64 >> 32);
- lo = uint32_t(seed64 & 0xFFFFFFFF);
- std::cout << "AES#1 created with seed " << std::setw(10) << hi << '-' << std::setw(10) << lo << std::endl;
- auto aes1 = new AES_COUNTER(hi, lo);
- seed64 += 1;
- hi = uint32_t(seed64 >> 32);
- lo = uint32_t(seed64 & 0xFFFFFFFF);
- std::cout << "AES#2 created with seed " << std::setw(10) << hi << '-' << std::setw(10) << lo << std::endl;
- auto aes2 = new AES_COUNTER(hi, lo);
- for (size_t i = 0; i < 16; ++i) {
- std::cout << std::setw(10) << (*aes1)() << ", " << std::setw(10) << (*aes2)() << std::endl;
- }
- std::cout << std::endl;
- // Scenario #4 - PSEUDO_DES seeded from PSEUDO_DES output (not obviously correlated)
- hi = (*pdes1)();
- lo = (*pdes1)();
- std::cout << "PDES#3 created with seed " << std::setw(10) << hi << '-' << std::setw(10) << lo << std::endl;
- auto pdes3 = new PSEUDO_DES(hi, lo);
- seed64 += 1;
- hi = (*pdes1)();
- lo = (*pdes1)();
- std::cout << "PDES#4 created with seed " << std::setw(10) << hi << '-' << std::setw(10) << lo << std::endl;
- auto pdes4 = new PSEUDO_DES(hi, lo);
- for (size_t i = 0; i < 16; ++i) {
- std::cout << std::setw(10) << (*pdes3)() << ", " << std::setw(10) << (*pdes4)() << std::endl;
- }
- std::cout << std::endl;
- // Scenario #5 - AES_COUNTER sseded from AES_COUNTER output (not obviously correlated)
- hi = (*aes1)();
- lo = (*aes1)();
- std::cout << "AES#3 created with seed " << std::setw(10) << hi << '-' << std::setw(10) << lo << std::endl;
- auto aes3 = new AES_COUNTER(hi, lo);
- seed64 += 1;
- hi = (*aes1)();
- lo = (*aes1)();
- std::cout << "AES#4 created with seed " << std::setw(10) << hi << '-' << std::setw(10) << lo << std::endl;
- auto aes4 = new AES_COUNTER(hi, lo);
- for (size_t i = 0; i < 16; ++i) {
- std::cout << std::setw(10) << (*aes3)() << ", " << std::setw(10) << (*aes4)() << std::endl;
- }
- std::cout << std::endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment