I want to generate different random numbers . I used srand and rand , but in my output some numbers are identical .
How to do with srand to generate different numbers ?
#include<iostream>
#include<time.h>
#include <windows.h>
int main(){
time_t t;
std::vector<int> myVector;
srand((unsigned)time(NULL));
for (int i = 0; i < 40; i++){
int b = rand() % 100;
myVector.push_back(b);
std::cout << myVector[i] << std::endl;
}
Sleep(50000);
}
Aucun commentaire:
Enregistrer un commentaire