I want to assign different -random- values (index) to populate a vector. Each time I run the program, it produces a different random value. But, it produces the same random value in each iteration of the loop for the same run.
this is my code :
void hire (vector<PersonType> &salaryMan, vector<CompanyType> &company){
double payment;
string role;
int i;
int j;
for (int x =0; x <5; x++){
i =randomizeEmp(salaryMan);
payment =salaryMan[i].getSalary();
role =salaryMan[i].getTitle();
j =randomizeEmp(salaryMan);
salaryMan[j].setTitle(role);
salaryMan[j].setSalary(payment);
company[x].employee.push_back(salaryMan[j]);
}
}
int randomizeEmp(vector<PersonType> &v){
double i;
int minNumOfEmp =0;
unsigned seed =time(NULL);
srand(seed);
i =minNumOfEmp +rand()% ((v.size()-1) - minNumOfEmp);
cout <<i<<endl;
return i;
}
My output is the following: CompanyA Florida Miami 100 Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
CompanyB NewYork NewYork 101 Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
CompanyC California SanJose 102 Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
CompanyD Texas Dallas 103 Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
CompanyE Florida Talahasse 104 Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Linette Lefevers 529 PartnerG 600000
Aucun commentaire:
Enregistrer un commentaire