Boost logo

Boost Users :

From: Joshua Little (ljoshua_at_[hidden])
Date: 2004-06-24 00:15:14

Hi all,
I'm trying to use the randome number generators but I am having some
problems. I'm using boost 1.31.0 and gcc 3.2 on Windows 2000. Here is my
code :
    printf(" Die \n ");
    //std::cout << "Die Rolls" << std::endl;
    try {
         boost::mt19937 rng; // produces randomness out
of thin air
                                              // see pseudo-random
number generators
          boost::uniform_int<> six(1,6); // distribution that maps
to 1..6
                                              // see random number
          boost::variate_generator<boost::mt19937, boost::uniform_int<>
> die(rng, six); // glues randomness with mapping
        int x = die();
        printf(" Die %d\n ",x);

     catch(...) {
         std::cout << "exception" << std::endl;
         printf(" Die exception \n ");

I basically copied the example code off the web site to see if I could
get it to work but I'm not having any luck. If I have the
variate_generator defined as above I do not not get any output to the
console after the declaration of die. I tried printf's and stream output
but neither works, I never see the "Die %d" printed out and I do not see
either of the outputs in the catch(...) section. printed either. I even
had a throw in the try block at one time to see if it could get to the
catch section and did not see output. When I remove the die declaration
(and comment out the code that uses it) but leave the generator and the
distribution then I can see output again and if I throw after the
distribution declaration then I see both output statements in the catch
block. So it seems like if I have the variate generator declared then I
can't see any output after that, but when I comment it out I can see
output again. I'm not sure what I'm doing wrong since I am basically
copying a pretty simple example from the book I just can't get it to
work. Ah and just incase this makes a difference I'm running this code
as a test case in a boost test suite. I wanted to try to get it to work
there before putting it into my main app.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at