Skip to content

Random Numbers

Leeor Dicker edited this page Mar 27, 2017 · 3 revisions

NAS2D originally provided a Random interface with a Mersenne Twister implementation for easy generation of random numbers. The C++11 standards, however, provide a much better implementation and so this interface was deprecated in favor of using the standard library.

For information on how to use the C++11 random interface, see <random>.

Example code using a Mersenne Twister PRNG engine:

#include <iostream>
#include <random>

int main(int argc, char *argv[])
{
	std::random_device rd;
	std::mt19937 generator(rd());
	std::uniform_int_distribution<int> dist(1, 6);

	for(int i = 0; i < 10; ++i)
		std::cout << dist(generator) << std::endl;

	return 0;
}
Clone this wiki locally