| 1 | #include <boost/random/taus88.hpp>
|
|---|
| 2 | #include <boost/random/discrete_distribution.hpp>
|
|---|
| 3 | #include <list>
|
|---|
| 4 | #include <iostream>
|
|---|
| 5 | #include <iterator>
|
|---|
| 6 | #include <algorithm>
|
|---|
| 7 |
|
|---|
| 8 | std::list<int> l;
|
|---|
| 9 |
|
|---|
| 10 | std::list<double> probs;
|
|---|
| 11 |
|
|---|
| 12 | int main()
|
|---|
| 13 | {
|
|---|
| 14 | l.push_back(-5); l.push_back(-3); l.push_back(-1); l.push_back(0); l.push_back(2); l.push_back(4); l.push_back(6);
|
|---|
| 15 | probs.push_back(-100); probs.push_back(-50); probs.push_back(-5); probs.push_back(0); probs.push_back(12); probs.push_back(75); probs.push_back(150);
|
|---|
| 16 | auto minmax = std::minmax_element(probs.begin(), probs.end());
|
|---|
| 17 | for (auto it = probs.begin(); it != probs.end(); ++it)
|
|---|
| 18 | {
|
|---|
| 19 | (*it) += std::abs(*(minmax.first)) + (std::abs(*(minmax.first)) + std::abs(*(minmax.second))) / 2.0 + 1;
|
|---|
| 20 | }
|
|---|
| 21 | std::cout << "Weights:";
|
|---|
| 22 | for (auto it = probs.begin(); it != probs.end(); ++it)
|
|---|
| 23 | {
|
|---|
| 24 | std::cout << " " << *it;
|
|---|
| 25 | }
|
|---|
| 26 | std::cout << std::endl;
|
|---|
| 27 | boost::random::taus88 rng(0x13141516);
|
|---|
| 28 | boost::random::discrete_distribution<> distr(probs.begin(), probs.end());
|
|---|
| 29 |
|
|---|
| 30 | std::cout << "Probabilities:";
|
|---|
| 31 | for (auto it = distr.probabilities().begin(); it != distr.probabilities().end(); ++it)
|
|---|
| 32 | {
|
|---|
| 33 | std::cout << " " << *it;
|
|---|
| 34 | }
|
|---|
| 35 | std::cout << std::endl;
|
|---|
| 36 | std::cout << "Rollin..." << std::endl;
|
|---|
| 37 | for (int i = 0; i < 1000; ++i) {
|
|---|
| 38 | std::list<int>::iterator rolled = l.begin();
|
|---|
| 39 | std::advance(rolled, distr(rng));
|
|---|
| 40 | std::cout << "Rolled " << *rolled << std::endl;
|
|---|
| 41 | }
|
|---|
| 42 | return 0;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|