我用matlab编写了一个程序,用来生成0到1之间的随机数.我只用matlab中的运行测试来测试它,结果是序列是随机的.我也见过直方图,他们有β分布.我想测试这个rng和其他测试,比如diehard,ent或nist,但我不知道怎么做.有人可以解释如何使用它们,或建议我一些其他随机性测试.谢谢
我测试了gcc C++标准库的Mersenne twister实现.它优于线性同余生成器和C rand,这很可能是LCG.增强文档似乎也给出了类似的结果,但更有利于Mersenne twister.有谁能解释一下?
#include <cstdlib>
#include <iostream>
#include <chrono>
#include <random>
class Timer
{
private:
std::chrono::high_resolution_clock::time_point start_time;
std::chrono::high_resolution_clock::time_point stop_time;
public:
void start()
{
start_time = std::chrono::high_resolution_clock::now();
}
void stop()
{
stop_time = std::chrono::high_resolution_clock::now();
}
double measure()
{
using namespace std::chrono;
return duration_cast<microseconds>
(stop_time - start_time).count() / 1000000.0;
}
};
template<typename T>
class Random
{
private:
T generator;
public:
Random()
: generator
(std::chrono::high_resolution_clock::now().time_since_epoch().count())
{
}
int generate_integer(int begin, int end)
{
return std::uniform_int_distribution<int>(begin, end - 1)(generator); …Run Code Online (Sandbox Code Playgroud) 我听到一些人说,rand()即使在使用srand()获得种子后,使用也很糟糕。为什么呢?我想知道事情是如何发生的......还有另一个问题很抱歉......但是有什么替代方法呢?