/**
* Parallel Code Count
* random_string.h
* Random string generator template.
*/
#pragma once
#include <string>
#include <random>
#include <algorithm>
// uses given distribution (uniform by default) and random generator
template <class Distr = std::uniform_int_distribution<unsigned char>, class Rng = std::mt19937>
class RandomString
{
public:
RandomString() {}
explicit RandomString(unsigned seed)
: rng(seed) {}
std::string operator()(std::size_t length)
{
std::string result(length, '\0');
std::generate(result.begin(), result.end(),
[this]() { return static_cast<char>(distr(rng)); });
return std::move(result);
}
private:
Rng rng;
Distr distr;
};