-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntToChar.cpp
More file actions
108 lines (86 loc) · 2.75 KB
/
IntToChar.cpp
File metadata and controls
108 lines (86 loc) · 2.75 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* \file IntToChar.cpp
* \brief
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
std::string
str(const size_t cuiLength)
{
const bool is_letters = true;
const bool is_numbers = true;
const bool is_symbols = true;
std::string sRes;
// the shortest way to do this is to create a string, containing
// all possible values. Then, simply add a random value from that string
// to our return value
std::string allPossible; // this will contain all necessary characters
if (is_letters) {
for (int i = 65; i <= 90; i++) {
allPossible += static_cast<char>(i);
allPossible += static_cast<char>(i + 32); // add a lower case letter, too!
}
}
if (is_numbers) {
for (int i = 48; i <= 57; i++) {
allPossible += static_cast<char>(i);
}
}
if (is_symbols) { // if you want symbols, we'll add symbols (note, their ASCII values are scattered)
for (int i = 33; i <= 47; i++) {
allPossible += static_cast<char>(i);
}
for (int i = 58; i <= 64; i++) {
allPossible += static_cast<char>(i);
}
for (int i = 91; i <= 96; i++) {
allPossible += static_cast<char>(i);
}
for (int i = 123; i <= 126; i++) {
allPossible += static_cast<char>(i);
}
}
// get the number of characters to use (used for rand())
size_t numberOfPossibilities = allPossible.size();
for (size_t i = 0; i < cuiLength; ++ i) {
sRes += allPossible[rand() % numberOfPossibilities];
}
// std::random_shuffle(sRes.begin(), sRes.end());
return sRes;
}
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
//const std::string sBucketA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//std::cout << "Ansi: "<< std::endl;
//for (size_t i = 0; i < sBucketA.size(); ++ i ) {
// std::cout << sBucketA.at(i) << ": " << (int)sBucketA.at(i) << std::endl;
//}
//const std::wstring sBucketW = L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//std::wcout << L"Unicode: "<< std::endl;
//for (size_t i = 0; i < sBucketW.size(); ++ i ) {
// std::wcout << sBucketW.at(i) << L": " << (int)sBucketW.at(i) << std::endl;
//}
srand(time_t(NULL));
for (size_t i = 0; i < 10; ++ i ) {
std::cout << str(10) << std::endl;
}
return 0;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
/**
\C$li,IZ..
FiW.yKL'JS
>[$\KY;i&1
n[6Mtdb4@;
"~ngDe8Oe;
|{a!?kV}Tu
z$QhLbYm\s
S>!"A(C]oH
b0FCKMz"L`
F-]'kHC)%`
*/
#endif