Generate¶
template <typename RNG, typename Iterator>
constexpr auto pxart::generate(RNG&& rng, Iterator first, Iterator last);
For all iterated elements rng()
is called and used as new value. This function can specialized for other types to provide more efficient implementations.
Include Scheme¶
#include <pxart/algorithm.hpp>
Example¶
#include <iomanip>
#include <iostream>
#include <random>
#include <vector>
//
#include <pxart/algorithm.hpp>
#include <pxart/mt19937.hpp>
#include <pxart/uniform.hpp>
using namespace std;
int main() {
pxart::mt19937 rng{random_device{}};
for (size_t i = 0; i < 10; ++i) {
vector<char> letters(20);
// Call generate algorithm to generate random 20-character-wide vector.
pxart::generate([&rng]() { return uniform<char>(rng, 'a', 'z'); },
begin(letters), end(letters));
for (auto c : letters) cout << c;
cout << '\n';
}
}
Last update: January 18, 2021