简体   繁体   中英

Using std::tr1::normal_distribution in Qt

I would like to generate numbers with normal_distribution in c++11. Using Qt 4.8 MinGW. I have added the next line

QMAKE_CXXFLAGS += -std=c++0x

to my .pro file and then get next errors: 'swprintf::' has not been declared 'vswprintf::' has not been declared

TR1 really should be avoid when using C++11 as it was designed to meet the limitations of the previous standard. (also everything that was considered useful went on and became integrated into the standard.)

Luckily there is a comprehensive random number generation library in C++11 with normal distribution.

See here:

http://en.cppreference.com/w/cpp/numeric/random

#include <random>
:::
std::random_device rd;
std::normal_distribution<double> dist(0,99);
std::mt19937 engine(rd());
double a=dist(engine);

The exact error your getting look as though the particular implementation of TR1 isn't very good anyway. (missing include or missing namespace prefix).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM