dimanche 19 août 2018

How can I use Random in boost library? [duplicate]

I'm using linux ubuntu 18.04 I'm trying to run an example about the boost random library I found on their web site : here is the example:

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

 int main() {
     std::string chars(
         "abcdefghijklmnopqrstuvwxyz"
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
         "1234567890"
         "!@#$%^&*()"
         "`~-_=+[{]}\\|;:'\",<.>/? ");     
     boost::random::random_device rng;
     boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1);
     for(int i = 0; i < 8; ++i) {
         std::cout << chars[index_dist(rng)];
     }
     std::cout << std::endl;
 }

I get lots of errors, here is one of them:

undefined reference to 'boost::random::random_device::random_device()'

And here is the command I use to compile:

g++ main.cpp -o prog Any tip would help thank you




Aucun commentaire:

Enregistrer un commentaire