dimanche 24 janvier 2016

Formula used for function rand() in c++

I want to know what is the formula used for generating random numbers using the rand() function in C++. At first I though it would return random numbers every time, but it does not.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
    cout << "Hello world!" << endl;

    srand(9865);
    cout << rand() << "\n";
    return 0;
}

Here I thought that, maybe because of given seed number and that unknown formula, it will be showing same number.

But, when i removed "srand(9865);" and execute several times it is showing only "41" as output. Please explain me what is all going on here.




Aucun commentaire:

Enregistrer un commentaire