How does rand() work?

I don't see how a computer can create someone completely and actually "random"- I mean it must get a number from somewhere constant.

So I was wondering how does rand() work- where does it get the numbers from/how does it generate the numbers? Thanks
As far as I understand it, its a big list with random numbers.

Calling it gives you the next number...that's why you need to initialise it with srand() so your starting point in the list is not 1 everytime you run your program.
http://en.wikipedia.org/wiki/Linear_congruential_generator ,is how it works.
You could see srand as something that sets X0.
@ hamsterman,

Thanks for the link, I wasn't aware that the standard algorithm was so simple (or so crappy).

Of course I used to think there was a tiny little guy in the CPU flipping "two bits"! ;-]
It should be noted that there's nothing in the C standard (to my knowledge) that requires rand() to be implemented as an LCG. It could just as well be MT19937. It's just that all implementations go with LCG because it's fast, simple, and good enough for all applications that need random numbers but not good random numbers.
Topic archived. No new replies allowed.