Programmers usually use the random number generator provided by the OS, so it's usually OS dependent.
In Windows, you provide a "seed" value, and the generator uses that as a basis for generating "pseudorandom" numbers. I was unable to find any details on the algorithm Windows uses.
If you use the same seed, you'll get the same sequence of numbers.
So the key is to use a "random" seed value. The system clock works nicely for this, as the combination of year/month/day/hour/second/millisecond provides what is essentially a "random" seed. Other methods for choosing a seed exist.
Other methods for generating random numbers would be a white noise generator, or an amlifier with enourmous gain that essentially amplifies noise on the inputs, or taking data from a radiotelescope tuned to an arbitrary frequency...