1

On the site of www.boost.org i have found a way to generate a real random number . I write here the example they offer :

#include <boost/random/random_device.hpp>
#include <iostream>

int main()
{
boost::random::random_device gen;
std::cout << gen() << '\n';
}

I did the download of the last boost library and actually on the directory boost/random there is the file called random_device.hpp . Trying to compile to this 'simple' program with : g++ nameprogram.cpp . I have this error on the terminal:
/home/andrea/boost_1_66_0/boost/random/random_device.hpp:22:28: fatal error: boost/config.hpp: File o directory non esistente compilation terminated. The path in the beginning is right and File o directory non esistente means that they don't exist. What I am doing wrong ? Of course leaving only boost/random/random_device.hpp does not work too.

john
  • 85,011
  • 4
  • 57
  • 81
  • You need to follow the build instructions for Boost: _"A few libraries have optional separately-compiled binaries: __Boost.Random__ has a binary component which is only needed if you're using __random_device__."_. So for your program you need to build Boost and link with it. See: http://www.boost.org/doc/libs/1_66_0/more/getting_started/index.html – Richard Critten Feb 03 '18 at 14:04
  • Add `-I/path/to/boost` to compile flag. – llllllllll Feb 03 '18 at 14:05
  • _"What I am doing wrong ?"_ What exactly did you do when configuring boost? Also note that [Pseudo random number Generation](http://en.cppreference.com/w/cpp/numeric/random) is already part of the current c++ standard. –  Feb 03 '18 at 14:05
  • Do you really need boost here? There are standard random routines since C++11 http://en.cppreference.com/w/cpp/numeric/random – Holt Feb 03 '18 at 14:05
  • You could ask Andrea! They're probably right next to you in class and know all about using it in a Ubuntu VM and not using Boost at all: https://stackoverflow.com/questions/48591592/how-do-i-use-boost-random/48592524#48592524 – sehe Feb 03 '18 at 14:06
  • Why not just use [`std::random_device`](http://en.cppreference.com/w/cpp/numeric/random/random_device). It probably came from Boost. Note: for MinGW g++, maybe for g++ in general, define `_GLIBCXX_USE_RANDOM_TR1` before including ``. – Cheers and hth. - Alf Feb 03 '18 at 14:08
  • Oh, good idea for new B-film horror movie: [“It came from Boost”](https://www.youtube.com/watch?v=85xpN_Ohwqs). – Cheers and hth. - Alf Feb 03 '18 at 14:11
  • thanks to @sehe it was I was looking for . it seems to work even if I would like to understand how does it work! – computational Feb 03 '18 at 14:24
  • I linked to the resources you need to understand that. Just don't expect to understand the C++ compilation model fully in minutes. Take your time learning this new language. (Note: if you're in fact in the same course as Andrea, remind them to accept the answer if it helped :)) – sehe Feb 03 '18 at 14:25

0 Answers0