-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathshuffle_weighted_example.cpp
50 lines (39 loc) · 1.21 KB
/
shuffle_weighted_example.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
/*
Copyright (c) Alexander Zaitsev <[email protected]>, 2017
Distributed under the Boost Software License, Version 1.0. (See
accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
See http://www.boost.org/ for latest version.
*/
#include <vector>
#include <iostream>
#include <random>
#include <boost/algorithm/shuffle_weighted.hpp>
namespace ba = boost::algorithm;
int main ( int /*argc*/, char * /*argv*/ [] )
{
// WARNING: Example require C++11 or newer compiler
std::random_device rd;
std::mt19937 g(rd());
{
std::cout << "shuffle_weighted with iterators:\n";
std::vector<int> vec{1, 2, 3, 4, 5}, order{4, 2, 3, 1, 0};
ba::shuffle_weighted(vec.begin(), vec.end(), order.begin(), order.end(), g);
for (const auto& x : vec)
{
std::cout << x << ", ";
}
std::cout << std::endl;
}
{
std::cout << "shuffle_weighted with ranges:\n";
std::vector<int> vec{1, 2, 3, 4, 5}, order{4, 2, 3, 1, 0};
ba::shuffle_weighted(vec, order, g);
for (const auto& x : vec)
{
std::cout << x << ", ";
}
std::cout << std::endl;
}
return 0;
}