-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_random.cpp
62 lines (54 loc) · 1.64 KB
/
test_random.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// $HOME/bin/bin/g++ -std=c++14 -fdiagnostics-color=auto -o test_random test_random.cpp
#include <random>
#include "random" // n3742: Three <random>-related Proposals, v2
#include "random2"
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <iterator>
int
main()
{
std::vector<int> pop;
for (int i = -1000; i <= +1000; ++i)
pop.push_back(i);
for (int i = -1000; i <= +1000; ++i)
pop.push_back(2*i);
for (int i = -1000; i <= +1000; ++i)
pop.push_back(5*i);
using std::experimental::sample;
std::vector<int> out(200);
auto stop = sample(std::begin(pop), std::end(pop), std::begin(out), 100, std::mt19937{});
for (auto i : out)
std::cout << ' ' << std::setw(5) << i;
std::cout << '\n';
for (auto i = std::begin(out); i != stop; ++i)
{
if ((i - std::begin(out)) % 5 == 0)
std::cout << '\n';
std::cout << ' ' << std::setw(5) << *i;
}
std::cout << '\n';
std::vector<int> out2(200);
std::ostringstream osmpstr{};
for (int i = -1000; i <= +1000; ++i)
osmpstr << ' ' << i;
for (int i = -1000; i <= +1000; ++i)
osmpstr << ' ' << i;
for (int i = -1000; i <= +1000; ++i)
osmpstr << ' ' << i;
std::istringstream ismpstr{osmpstr.str()};
auto stop2 = sample(std::istream_iterator<int>{ismpstr}, std::istream_iterator<int>{},
std::begin(out2), 100, std::mt19937{});
for (auto&& i : out2)
std::cout << ' ' << std::setw(5) << i;
std::cout << '\n';
for (auto&& i = std::begin(out2); i != stop2; ++i)
{
if ((i - std::begin(out2)) % 5 == 0)
std::cout << '\n';
std::cout << ' ' << std::setw(5) << *i;
}
std::cout << '\n';
}