读文件得第一行的数字作为随机数的最大值。
随机数写入文件中,这个代码随机产生了1000个点对。
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<stdlib.h>
#include<time.h>
#define random(x) (rand()%x)
int main(int args, char **argv)
{
std::ifstream fin("/home/a.txt", std::ios::in);
std::ofstream fout("/home/b.txt", std::ios::out);
std::string line;
int up_bounder;
getline(fin, line);
int i=0;
std::stringstream word(line);
word>>up_bounder;
srand((int)time(0));
while(i<1000){
fout<<random(up_bounder)<<" "<<random(up_bounder)<<"\n";
++i;
}
fin.clear();
fin.close();
fout.clear();
fout.close();
return 0;
}