user2189331
user2189331

Reputation:

Robust Random Number Generation

I'm looking for a performant, reasonably robust RNG using no special hardware. It can use mathematical methods (Mersenne Twister, etc), it can "collect entropy" from the machine, whatever. On Linux/etc we have a drand48() which generates 48 random bits. I'd like a similar function/class for C++ or C# which can generate more than 32 bits of randomness and which low-order bits are equally as random as high-order bits.

It doesn't have to be cryptographically secure but it must not use or be based on the C-language rand() or .NET System.Random.

Any source code, links to sources, etc. would be appreciated! Failing that, what TYPE of RNG should I be looking for?

Upvotes: 42

Views: 2179

Answers (5)

nsanders
nsanders

Reputation: 12636

Watch out for the Gnu Scientific Library. It's licensed under the GPL rather than LGPL.

As other folks mentioned, the Boost random classes are a good start. Their implementation conforms to the PRNG code slated for TR1:

http://www.boost.org/doc/libs/1_35_0/libs/random/index.html http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1452.html

If you have a recent version of the G++ compiler, you may find the TR1 libraries already included

Upvotes: 7

Rohit Vipin Mathews
Rohit Vipin Mathews

Reputation: 11787

Boost.Random is my first choice for RNG

http://www.boost.org/doc/libs/random

Upvotes: 2

bames53
bames53

Reputation: 88155

C++11 has adopted a robust random number library based on boost.random. You can access a number of random number engines using different algorithms to meet your quality, speed, or size requirements. Quality implementations will even provide access to whatever non-deterministic RNG your platform offers via std::random_device.

In addition there are many adaptors to produce specific distributions, eliminating the need to do such manipulation by hand (something often done incorrectly).

#include <random>

Upvotes: 5

C. K. Young
C. K. Young

Reputation: 223003

For C++, Boost.Random is probably what you're looking for. It has support for MT (among many other algorithms), and can collect entropy via the nondet_random class. Check it out! :-)

Upvotes: 31

Mark Harrison
Mark Harrison

Reputation: 304434

The Gnu Scientific Library (GSL) has a pretty extensive set of RN generators, test harness, etc. If you're on linux, it's probably already available on your system.

Upvotes: 8

Related Questions