我试图在我的项目中生成范围(0,1)中的高质量随机数,我尝试uniform_real_distribution从此处的示例代码进行测试.当我运行它的代码它工作正常,但当我尝试修改相同的播种生成器,如:
#include <random>
#include <iostream>
#include <chrono>
using namespace std;
// obtain a seed from the system clock:
unsigned seed = static_cast<int> (chrono::system_clock::now().time_since_epoch().count());
// globally defining the generator and making it static for safety because in the
// actual project this might affect the flow.
static default_random_engine gen(seed);
uniform_real_distribution<double> distribution(0.0,1.0);
int main(){
const int nrolls=10000; // number of experiments
const int nstars=95; // maximum number of stars to distribute
const int nintervals=10; // number of intervals …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 INSEL 中创建一个用户定义的块,它需要 C++ 进行编程,并使用 gfortran 链接它。
我的程序中有以下代码
// Setting seed for random number generators
unsigned seed = static_cast<int> (std::chrono::system_clock::now().time_since_epoch().count());
Run Code Online (Sandbox Code Playgroud)
设置为我的随机数生成器的种子。当我使用 g++ (gcc v.5.1.0) 编译它时,它没有显示错误或警告。我的编译命令是
g++ -O0 -Wall -c -g3 -std=c++14 -fmessage-length=0 $(sourcesC)
Run Code Online (Sandbox Code Playgroud)
sourcecC 有我所有的 .cpp 程序。但是当我尝试使用 gfortran 将其链接到:
gfortran -shared -o C:\***\inselUB.dll -Wall -L./ -linselTools $(objects)
Run Code Online (Sandbox Code Playgroud)
我收到错误:
C:***\resources/../src/constants.h:54: 对 `std::chrono::_V2::system_clock::now()' 的未定义引用
collect2.exe:错误:ld 返回 1 退出状态 makefile:11:目标“inselUB”的配方失败
make: *** [inselUB] 错误 1
我只是这种类型接口的初学者。可能是一个简单的错误。有人能给我建议一个解决方案吗?
操作系统:Win 7