Re: where are the implementations for <random>?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I found

  http://eel.is/c++draft/rand.eng.mers

which, if it has been adopted by the Standard, seems in Points 6, 8 actually
to fully specify the seeding, from initial values as well as from
sequents (std::seed_seq), and thus, hopefully, actually seeding in both
forms seems well-defined by the standard. (Otherwise it would be a
strange oversight.)

Oliver

P.S. And it seems that the GCC implementation does what is described in
that document.


> Consider the following program MT.cpp:
> 
> #include <iostream>
> #include <random>
> #include <vector>
> #include <cstdint>
> 
> int main() {
>   typedef std::mt19937_64::result_type ui;
>   std::seed_seq s {ui(10),ui(10),ui(0)};
>   std::vector<std::uint32_t> seeds(3);
>   s.generate(seeds.begin(), seeds.end());
>   for (const auto x : seeds) std::cout << x << " ";
>   std::cout << "\n";
>   std::mt19937_64 g(s);
>   std::cout << g() << " " << g() << "\n";
> }
> 
> Compiled with
> > g++ --std=c++11 -Wall MT.cpp 
> it yields with gcc 4.7.4 and gcc 5.4
> 
> > ./a.out 
> 927367489 2598207009 681269367 
> 14538134740155241067 15440504459514664889
> 
> As far as I understand it, only the first line is defined by the standard,
> but not the second: how the seed-sequence is used by the generator g is up
> to the compiler.
> 
> Thus the need to do the seeding ourselves.
> 
> Oliver
> 




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux