mardi 28 avril 2015

Why "rand()" function prints always the same random values? [duplicate]

This question already has an answer here:

I got this code:

#include <stdio.h>
#include <conio.h>
int rand();

int main()
{
        int a = 1;

        while (a<=15)
        {
                printf("%d\n", rand());
                a++;
        }

        return 0;

}

Funny thing is that it always print the same list of numbers. I thought it would print different numbers each time - and I know there's must be some argument that makes that - but what surprised me is that the program knows exactly how to print the same values always.

So how is that possible, I mean, I'm just curious, seems like a sequence of number is already predefined into the executable.




Aucun commentaire:

Enregistrer un commentaire