| 1 |
// { dg-do run { target c++11 } } |
| 2 |
// { dg-require-cstdint "" } |
| 3 |
// |
| 4 |
// 2008-11-24 Edward M. Smith-Rowland <[email protected]> |
| 5 |
// |
| 6 |
// Copyright (C) 2008-2025 Free Software Foundation, Inc. |
| 7 |
// |
| 8 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 9 |
// software; you can redistribute it and/or modify it under the |
| 10 |
// terms of the GNU General Public License as published by the |
| 11 |
// Free Software Foundation; either version 3, or (at your option) |
| 12 |
// any later version. |
| 13 |
// |
| 14 |
// This library is distributed in the hope that it will be useful, |
| 15 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
// GNU General Public License for more details. |
| 18 |
// |
| 19 |
// You should have received a copy of the GNU General Public License along |
| 20 |
// with this library; see the file COPYING3. If not see |
| 21 |
// <http://www.gnu.org/licenses/>. |
| 22 |
|
| 23 |
// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers] |
| 24 |
// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] |
| 25 |
|
| 26 |
#include <sstream> |
| 27 |
#include <random> |
| 28 |
#include <testsuite_hooks.h> |
| 29 |
|
| 30 |
void |
| 31 |
test01() |
| 32 |
{ |
| 33 |
std::stringstream str; |
| 34 |
std::mersenne_twister_engine< |
| 35 |
unsigned long, 32, 624, 397, 31, |
| 36 |
0x9908b0dful, 11, |
| 37 |
0xfffffffful, 7, |
| 38 |
0x9d2c5680ul, 15, |
| 39 |
0xefc60000ul, 18, 1812433253ul> u, v; |
| 40 |
|
| 41 |
u(); // advance |
| 42 |
str << u; |
| 43 |
|
| 44 |
VERIFY( !(u == v) ); |
| 45 |
|
| 46 |
str >> v; |
| 47 |
VERIFY( u == v ); |
| 48 |
for (unsigned i = 0; i < 1000; ++i) |
| 49 |
VERIFY( u() == v() ); |
| 50 |
|
| 51 |
str.clear(); |
| 52 |
str << v; |
| 53 |
|
| 54 |
u(); |
| 55 |
u(); |
| 56 |
u(); |
| 57 |
|
| 58 |
str >> u; |
| 59 |
VERIFY( u == v ); |
| 60 |
for (unsigned i = 0; i < 1000; ++i) |
| 61 |
VERIFY( u() == v() ); |
| 62 |
} |
| 63 |
|
| 64 |
int main() |
| 65 |
{ |
| 66 |
test01(); |
| 67 |
return 0; |
| 68 |
} |