Line | |
---|
1 | #include <iostream> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <algorithm> |
---|
4 | #include <sys/time.h> |
---|
5 | void gen_random(std::string &s, const int len) { |
---|
6 | timeval t1; |
---|
7 | gettimeofday(&t1, NULL); |
---|
8 | std::srand(t1.tv_usec * t1.tv_sec); |
---|
9 | static const char alphanum[] = |
---|
10 | "0123456789" |
---|
11 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
---|
12 | "abcdefghijklmnopqrstuvwxyz"; |
---|
13 | |
---|
14 | s.resize(len); |
---|
15 | for (int i = 0; i < len; ++i) { |
---|
16 | s[i] = alphanum[std::rand() % (sizeof(alphanum) - 1)]; |
---|
17 | } |
---|
18 | } |
---|
19 | int main() |
---|
20 | { |
---|
21 | std::string s; |
---|
22 | for (int i=0; i<6; i++) |
---|
23 | { |
---|
24 | gen_random(s,8); |
---|
25 | std::cout << s << " "; |
---|
26 | } |
---|
27 | std::cout << std::endl; |
---|
28 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.