create random vectors c 2b 2b

Solutions on MaxInterview for create random vectors c 2b 2b by the best coders in the world

showing results for - "create random vectors c 2b 2b"
Felipe
16 Oct 2019
1#include <random>
2#include <algorithm>
3#include <iterator>
4#include <iostream>
5#include <functional>
6
7using namespace std;
8
9int main()
10{
11    // First create an instance of an engine.
12    random_device rnd_device;
13    // Specify the engine and distribution.
14    mt19937 mersenne_engine {rnd_device()};  // Generates random integers
15    uniform_int_distribution<int> dist {1, 52};
16
17    auto gen = [&dist, &mersenne_engine](){
18                   return dist(mersenne_engine);
19               };
20
21    vector<int> vec(10);
22    generate(begin(vec), end(vec), gen);
23
24    // Optional
25    for (auto i : vec) {
26        cout << i << " ";
27    }
28
29
30}
31