mercredi 17 février 2016

Rand() is generator the same number even though I called srand(time(NULL))

Here is my code

#include <iostream> //cout, cin
#include <time.h> // time
#include <stdlib.h> // srand(), rand()
using std::cout; //cout

int main()
{
    srand(time(NULL)); //Initializes a random seed
    int rand_number = rand() % 1 + 100; //Picks a random number between 1 and 100

    cout << rand_number << std::endl;
}

For some reason, it keeps giving me 100 when I generate the random number. Though I don't believe it should because I called srand(time(NULL)) to initialize a seed.




Aucun commentaire:

Enregistrer un commentaire