jeudi 25 août 2016

Generate a Random number every 2 seconds? C++ Srand

I am studying C++ in order to make a game and I was able to generate a random number every second using the functions of srand. But I wanted the number to be different every 2 second instead. How can I fix my code?

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <ctime>

using namespace std;

int main(int argc, char*argv[])
{
    srand(time(0)); 

    int i =rand()%100+1;0
    cout << i << endl; 
    return 0;
}




Aucun commentaire:

Enregistrer un commentaire