例1:
//第一次测试
int main(){
for (int i = 0; i < 10; ++i){
std::cout << rand() << " ";
}
std::cout << "This is the first test" << std::endl;
return 0;
}
//第二次测试
int main(){
for (int i = 0; i < 10; ++i){
std::cout << rand() << " ";
}
std::cout << "This is the second test" << std::endl;
return 0;
}
测试1结果:
测试2结果:
例2:
//测试1
int main(){
srand(unsigned(time(0)));
for (int i = 0; i < 10; ++i){
std::cout << rand() << " ";
}
std::cout << std::endl << "This is the first test" << std::endl;
return 0;
}
//测试2
int main(){
srand(unsigned(time(0)));
for (int i = 0; i < 10; ++i){
std::cout << rand() << " ";
}
std::cout << std::endl << "This is the second test" << std::endl;
return 0;
}
测试1结果:
测试2结果:
例3:
int main(){
for (int i = 0; i < 10; ++i){
srand(unsigned(time(0)));
std::cout << rand() << std::endl;
}
return 0;
}