#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
// cout << "You have entered " << argc << " arguments:" << "\n";
// for (int i = 0; i < argc; ++i) {
// cout << argv[i] << "\n";
// }
const char *seed = argv[1];
srand(*seed);
cout << "seed " << seed << endl;
int answer;
for (int i = 0; i < 10; i++) {
answer = rand() % 100;
cout << answer << endl;
}
return 0;
}
실행
$ ./rand_seed 1
seed 1
43
19
38
8
48
58
62
71
76
26
$ ./rand_seed 1
seed 1
43
19
38
8
48
58
62
71
76
26
$ ./rand_seed 2
seed 2
50
68
11
66
78
30
6
49
99
88
$ ./rand_seed 2
seed 2
50
68
11
66
78
30
6
49
99
88
동일한 seed 값에서는 동일한 램덤 패턴으로 랜덤 값이 생성된다.