-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsequence_util.h
More file actions
53 lines (45 loc) · 1.27 KB
/
Copy pathsequence_util.h
File metadata and controls
53 lines (45 loc) · 1.27 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef CPP_ALGORITHM_SEQUENCE_UTIL_H
#define CPP_ALGORITHM_SEQUENCE_UTIL_H
#include <iostream>
#include <random>
#include <vector>
namespace Util
{
/**
* \brief Print sequence to standard output.
* \param seq input sequence
*/
void PrintSequence(const std::vector<int>& seq);
/**
* \brief Generate sequence.
* \param size sequence size
* \param min minimum value bound
* \param max maximum value bound
* \return result sequence
*/
std::vector<int> GenerateSequence(int size, int min, int max);
}
// ----------------------------------------------------------------------------
inline void Util::PrintSequence(const std::vector<int>& seq)
{
for (const int element : seq)
{
std::printf("%d ", element);
}
std::cout << std::endl;
}
// ----------------------------------------------------------------------------
inline std::vector<int> Util::GenerateSequence(const int size, const int min, const int max)
{
std::vector<int> seq;
std::random_device rd;
std::mt19937 generator(rd());
std::uniform_int_distribution<> distribution(min, max);
seq.reserve(size);
for (int count = 0; count < size; ++count)
{
seq.push_back(distribution(generator));
}
return seq;
}
#endif