Modify

Opened 16 years ago

Closed 16 years ago

#11 closed Bugs (Fixed)

why not using mt19937?

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

Description

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 
documentation,
 *
 * 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 
library.
 */

#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 
boost::minstd_rand
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
(generator);
  std::cout.setf(std::ios::fixed);

  // 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::
  generator.seed(
#ifndef BOOST_NO_STDC_NAMESPACE
		 std::
#endif
		 time(0));

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

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

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

#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
  {
    // save the generator state for future use,
    // can be read again at any time via operator>>
    std::ofstream file("rng.saved", 
std::ofstream::trunc);
    file << generator;
  }
#endif
  // 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:
"
d:\project\boost_1_25_0
\boost\random\mersenne_twister.hpp(86) : error C2064: 
term does not evaluate to a function
        d:\project\boost_1_25_0
\boost\random\mersenne_twister.hpp(66) : see 
reference to function template instantiation 'void 
__thiscall boost::random::mersenne_twister<unsigned 
long,624,397,31,-1727483681,11,7,-1658038656,15,-
272236544,18,-9485417
30>::seed(const int &)' being compiled
"

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

Attachments (0)

Change History (1)

comment:1 Changed 16 years ago by jmaurer

Status: assignedclosed
Logged In: YES 
user_id=53943

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

Please check out the CVS.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain jmaurer.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.