This code works alright if I just have it as is , in main. I can take out the method call to do_something() and just do a cout and it performs as expected. I desire to build it into a modular randomizer method and failing. Can someone correct me so that I am correctly calling the mersenne twister, or even a simpler way to implement a modular rand function ? I know I've overdone the libraries in the h file. Thank you.
randomizer.h:
'''
#include <iostream>
#ifndef RAND_H_
#define RAND_H_
#include <random>
#include <string>
#include <vector>
#include <functional>
using namespace std;
class Randomizer {
public:
gen();
void do_something() {}
};
#endif
'''
randomizer.cpp:
'''
#include <random>
#include <iostream>
#include "randomizer.h"
using namespace std;
int main()
{
random_device rd; // non-deterministic generator
// to seed mersenne twister.
// replace the call to rd() with a
// constant value to get repeatable
Randomizer m;
m.do_something();
}
'''
main.cpp
'''
#include <random>
#include <iostream>
#include "randomizer.h"
using namespace std;
int main()
{
random_device rd; // non-deterministic generator
// to seed mersenne twister.
// replace the call to rd() with a
mt19937 gen(rd()); // constant value to get repeatable
Randomizer m;
m.do_something();
}
'''
Aucun commentaire:
Enregistrer un commentaire