jeudi 28 avril 2016

Generate different random numbers

I want to generate different random numbers . I used srand and rand , but in my output some numbers are identical .

This is my output : enter image description here

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