Hi everybody
I'm using Borland C++ 5.02 on windows 7.
I want to generate random numbers according to different distributions such as normal, uniform and ...
I found that I have to use <random.h> library. So, at first I entered the example code in http://www.cplusplus.com/reference/random/uniform_int_distribution/.
the code is as follows:
#include <random>
void main()
{
constint nrolls = 10000; // number of experiments
constint nstars = 95; // maximum number of stars to distribute
default_random_engine generator;
uniform_int_distribution <int> distribution(0,9);
int p[10]={0};
for (int i=0; i<nrolls; ++i) {
int number = distribution(generator);
++p[number];
}
cout << "uniform_int_distribution (0,9):" << endl;
for (int i=0; i<10; ++i)
cout << i << ": " << string('*',p[i]*nstars/nrolls) << endl;
return;
}
and when I compile the code I receive these errors:
Info :Compiling C:\BC5\BIN\foo.cpp
Error: test of distr.cpp(7,34):Undefined symbol 'default_random_engine'
Error: test of distr.cpp(7,34):Statement missing ;
Error: test of distr.cpp(8,29):Undefined symbol 'uniform_int_distribution'
Error: test of distr.cpp(8,33):Expression syntax
Error: test of distr.cpp(13,31):Call to undefined function 'distribution'
Error: test of distr.cpp(13,41):Undefined symbol 'generator'
I was wondering if anyone might be able to help me.
According to wikipedia, Borland C++ 5.02 was released in 1999.
The <random> feature was introduced as part of C++11, that is a 2011 update to the standard.
I suggest you leave behind the outdated Borland compiler and switch to an up-to-date IDE/compiler such as code::blocks or Orwell DevC++ which will give you access to these most recent C++ features.
I Installed (codeblocks-13.12mingw-setup-TDM-GCC-481.exe) from sourceforge.net while it's release date is 27 Dec 2013.
I entered the aforementioned code and received this error message:
c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\c++0x_warning.h|32|error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
what should I do?
I appreciate you if you help me.