Opened 17 years ago

Closed 17 years ago

#11 closed Bugs (Fixed)

why not using mt19937?

Reported by: nobody Owned by: jmaurer
Milestone: Component: random
Version: None Severity:
Keywords: Cc:


i complie the random_demo.cpp, everything is ok.
( VC6 + SP5 )

following is code:

/* boost random_demo.cpp profane demo
 * Copyright Jens Maurer 2000
 * Permission to use, copy, modify, sell, and 
distribute this software
 * is hereby granted without fee provided that the 
above copyright notice
 * appears in all copies and that both that copyright 
notice and this
 * permission notice appear in supporting 
 * Jens Maurer makes no representations about the 
suitability of this
 * software for any purpose. It is provided "as is" 
without express or
 * implied warranty.
 * $Id: random_demo.cpp,v 1.5 2001/05/31 17:19:14 
jmaurer Exp $
 * A short demo program how to use the random number 

#include <iostream>
#include <fstream>
#include <ctime>            // std::time

#include <boost/random/linear_congruential.hpp>
#include <boost/random/uniform_smallint.hpp>
#include <boost/random/uniform_01.hpp>

// try boost::mt19937 or boost::ecuyer1988 instead of 
typedef boost::minstd_rand base_generator_type;

// This is a reproducible simulation experiment.
void experiment(base_generator_type & generator)
  boost::uniform_smallint<base_generator_type> die
(generator, 1, 6);

  // you can use a STL Iterator interface
  for(int i = 0; i < 10; i++)
    std::cout << *die++ << " ";
  std::cout << '\n';

int main()
  // initialize by reproducible seed
  base_generator_type generator(42);

  std::cout << "10 samples of a uniform distribution 
in [0..1):\n";
  boost::uniform_01<base_generator_type> uni

  // you can also use a STL Generator interface
  for(int i = 0; i < 10; i++)
    std::cout << uni() << '\n';

  // change seed to something else
  // Note: this is not the preferred way of hacking 
around missing std::

  std::cout << "\nexperiment: roll a die 10 times:\n";
  base_generator_type saved_generator = generator;

  std::cout << "redo the experiment to verify it:\n";

  // after that, both generators are equivalent
  assert(generator == saved_generator);

    // save the generator state for future use,
    // can be read again at any time via operator>>
    std::ofstream file("rng.saved", 
    file << generator;
  // Some compilers don't pay attention to 
std:3.6.1/5 and issue a
  // warning here if "return 0;" is omitted.
  return 0;

however, i use 

typedef boost::boost::mt19937 base_generator_type;

this sentence instead of old

typedef boost::minstd_rand base_generator_type;

sentence, complier report error:
\boost\random\mersenne_twister.hpp(86) : error C2064: 
term does not evaluate to a function
\boost\random\mersenne_twister.hpp(66) : see 
reference to function template instantiation 'void 
__thiscall boost::random::mersenne_twister<unsigned 
30>::seed(const int &)' being compiled

i don't know why???who can tell me?

Change History (1)

comment:1 Changed 17 years ago by jmaurer

Status: assignedclosed
Logged In: YES 

I've checked in changes to random_demo.cpp which should
allow flawless interaction with mt19937.

Please check out the CVS.
Note: See TracTickets for help on using tickets.