Better RNG

Sep 20, 2011 at 7:56am
I've been trying to find a better random number generator than the built-in one. Many people have said that the Mersenne Twister is good, but I can't get it to work, either due to miscoding or something I need to download. If there's another one, or someone knows how to get it to work, please let me know.
Sep 20, 2011 at 8:58am
boost has a random number generator library. You could try that. (It's also the one that's going into the next C++ standard so...)
Sep 20, 2011 at 12:15pm
The GMP library http://gmplib.org/ is simple to use and link against, and comes with a nice RNG.
Sep 20, 2011 at 12:30pm
closed account (1vRz3TCk)
I've been trying to find a better random number generator than the built-in one.

Better in what respect?
Sep 20, 2011 at 1:28pm
I assume distribution?
Sep 20, 2011 at 1:43pm
closed account (1vRz3TCk)
Also, what is the PRNG going to be used for?
Sep 20, 2011 at 2:17pm
closed account (DSLq5Di1)
Assuming you have a compiler that supports C++0x/TR1,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <random>
using namespace std;

int main()
{
    random_device seed;
    mt19937 engine(seed()); // mersenne twister

    uniform_int_distribution<> dist(0, 100);
 
    for (int i = 0; i < 10; i++)
    {
        cout << dist(engine) << endl;
    }

    return 0;
}
Topic archived. No new replies allowed.