Most random generators are based on the time ( normally milliseconds ) the host computer has been active - and then incremented each time RAND is called.
This is why most languages also provide a "seed" function which allows the user to reseed the generator. In PHP if you call SEED(1000) and then RAND you will always get the same value. The more diverse values you use in SEED the better the random element is going to be - mix the time the site is visited with the LONG IP will give good results.
I did hear of a truely random generator which took an image of a lava lamp and generated a value based on where the blobs of lava were! Bit OTT but very random!