Skip to content

Instantly share code, notes, and snippets.

@mkamotsu
Created May 21, 2013 07:56
Show Gist options
  • Save mkamotsu/5618196 to your computer and use it in GitHub Desktop.
Save mkamotsu/5618196 to your computer and use it in GitHub Desktop.
// g++ -std=c++0x random.cpp -o random
#include <iostream>
#include <random>
#include <functional>
class RandomGenerator {
private:
std::mt19937 e_;
std::uniform_real_distribution<long double> dist_;
public:
RandomGenerator(long double min, long double max)
: dist_(min, max)
{
std::random_device rd;
e_.seed(rd());
}
RandomGenerator(long double min, long double max, unsigned long seed)
: e_(seed), dist_(min, max) {}
long double operator()() {
return dist_(e_);
}
};
int main(int argc, char** argv) {
using std::cout;
using std::endl;
RandomGenerator gen1(0, 1);
RandomGenerator gen2(0, 1, 0);
for (int i=0; i<10; ++i) {
cout << gen1() << endl;
}
cout << endl;
for (int i=0; i<10; ++i) {
cout << gen2() << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment