I have discovered what seems to be a bug in the <random> header. Have a look
at this sample program:
#include <random>
#include <iostream>
int main()
{
// Uniform distribution using mt19937 generator with 2^19937-1 cycle.
typedef std::tr1::variate_generator<std::tr1::mt19937&,
std::tr1::uniform_int<int>> UniformReal6419937;
std::tr1::uniform_int<int> distr(0, 2);
std::tr1::mt19937 mt19937;
UniformReal6419937 generator(mt19937, distr);
for( int i=0; i<20; i++ )
{
std::cout << generator() << std::endl;
}
return 0;
}
I expect the output to be a mixture of 0, 1, and 2. However, this is what is
printed:
0
0
0
0
0
0
0
0
-1
0
0
-1
0
0
-1
0
0
0
0
0
Changing to boost writes this:
1
1
0
0
2
2
2
2
2
0
0
2
2
0
2
2
2
0
1
1
This might have been reported already, otherwise maybe one of the MVPs could
file it to Microsoft?
Thanks in advance!
--
Daniel
variate_generator was broken in VC9 SP1. We hotfixed this
(http://blogs.msdn.com/vcblog/archive/2008/12/17/vc9-sp1-hotfix-for-the-vector-function-ft-crash.aspx
), but the hotfix package was broken, so we're regenerating it.
However, I once tried to use variate_generator<mt19937, uniform_int<int> >,
and P.J. Plauger (PJP) told me this:
"The program is ill formed, according to TR1, because you can't convert all
values of the engine type (unsigned long) to the distribution type (int).
Converting the engine max() to int makes it -1, which leads to a zero divide
and +/- Inf generated values, which then get mapped to the whimsical int
values.
Note that variate_generator has been removed from C++0X."
As you may know, Microsoft has licensed its C++ Standard Library and TR1
implementations from Dinkumware; PJP maintains Dinkumware's implementations,
while I work with him to integrate his changes into Microsoft's sources.
Stephan T. Lavavej
Visual C++ Libraries Developer
"Daniel Lidström" <som...@microsoft.com> wrote in message
news:eAhmiHJd...@TK2MSFTNGP03.phx.gbl...
Many thanks for your answer Stephan.
--
Daniel