I'm trying to create a deterministic hash generator using a pseudo random number sequence with the mt19937
engine in the <random>
library. Therefore, I need to get the same sequence of numbers every time I feed the engine with the same seed.
My code looks like this:
#include <iostream>
#include <random>
#include <time.h>
#include <Windows.h>
int randomnumber = 0;
int main(){
std::random_device rd;
std::uniform_int_distribution<int> dist(0, 1);
std::mt19937(123);
for (int i = 0; i < 32; i++) {
randomnumber |= ((unsigned)(dist(rd)) << i);
}
std::cout << (unsigned int)randomnumber << std::endl;
std::mt19937(112);
for (int i = 0; i < 32; i++) {
randomnumber |= ((unsigned)(dist(rd)) << i);
}
std::cout << (unsigned int)randomnumber << std::endl;
std::mt19937(123);
for (int i = 0; i < 32; i++) {
randomnumber |= ((unsigned)(dist(rd)) << i);
}
std::cout << (unsigned int)randomnumber << std::endl;
return 0;
}
I tried setting the seed every time I generated a new hash, but the random number sequence was still different.
The outputs are:
1126954929
3745251263
3753639871