language: C++11 (gcc-4.7.2)
date: 175 days 1 hour ago
link:
visibility: private
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
#include <algorithm>
#include <ctime>
#include <functional>
#include <iostream>
#include <random>
#include <string>
 
int main()
{
    const std::size_t defaultStringLength = 50;
 
    //std::random_device seed;
    //std::mt19937 prne(seed());
    // random_device is way better, but no access to hardware at ideone
    std::mt19937 prne( std::time(NULL) );
 
    std::vector<double> bounds = {'A', 'Z'+1, 'a', 'z'+1};
    std::vector<double> weights = {   1,  0,   1};
    std::piecewise_constant_distribution<> d(bounds.begin(), bounds.end(), weights.begin());
 
    std::string s(defaultStringLength, ' ');
 
    std::generate(s.begin(), s.end(), bind(d, ref(prne)));
 
    std::cout << s << '\n';
}