Hello, I am trying to make a relatively unbiased random number generator that generates a random number between 1 and 9. The following code is a comparison between a Mersenne Twister algorithim and and a RAND algorithm. The MT keeps outputting a '6', whereas the RAND outputs more random numbers, although I suspect it's more biased than the MT here (if MT worked). My hunch is that this is a seeding problem.
#include <iostream>
#include <random>
#include <time.h>
usingnamespace std;
int main()
{
mt19937(time(0));
srand(time(0));
cout << "A random number will be generated between 1 and 9" << endl;
std::random_device rd; // obtain a random number from hardware
std::mt19937 eng(rd()); // seed the generator
std::uniform_int_distribution<> distr(1, 9); // define the range
cout << distr(eng) << endl;
int n = 1 + (rand() % ( 9 - 1 + 1 ));
cout << n << endl;
}