Is there any mathematical formula which gives a better or worse approximation of Mains Hum? The idea is to programatically generate the sound.
As heard within amplifiers, the frequency can be 100/120Hz (2nd harmonic of 50 or 60Hz) because of the rectification process when converting AC to DC to power said amplifiers. There can also be a component that is the third harmonic of 50/60Hz as well and this is magnetically "coupled" from the AC transformer inside an amplifier.
There are all sorts of variations too. Due to the rectification process and the magnetics of the transformer the second or third harmonic may well have overtones because of the peaky nature of current flowing into the rectifier when charging reservoir capacitors.
So, it depends on what does the picking up and how close it is to the source. A guitar pickup (non humbucker of course!) may pick up a lot of 50H/60Hz from the current in wiring in the walls of your building.
Why not take a recording of it and use some software to analyse the frequency spectra then generate sinewaves to recreate the components found in the spectra. Or just loop the sound you recorded as your "sound".
It's a 50 or 60hz sine wave (depending on power frequency). You aren't going to get more accurate than that. The harmonics are going to depend on the particular power generation and will vary based on uncontrolled variations in both the grid and how the hum is actually being introduced in to the signal.
The fastest way to solve this problem is simply sample a mains hum / ground loop and work with that. I would start by recording 5 minutes of ground hum. Then find a section of about a minute long that loops nicely (make sure that the start and end points are aligned to either both a rising or falling zero-crossing). Then progressively shorten the sample until it no longer sounds good. You should be able to do this easily in Audacity. You can even generate a 50Hz or 60Hz sine wave in Audacity and play around with adding various harmonics until you get something that you like.
The slower way would be to still start with the mains hum, but instead of shortening below a 1-minute loop, use a Fourier transformation to determine the first few Cosine waves that make up your signal. Then you just code up an oscillator that is made up of those Cosine waves and their coefficients. You probably need fewer than 10 coefficients, but again you will want to experiment for yourself and pick what you like.
Take the Fourier Transformation of the recorded sound and you can reconstruct it from data.
Wikipedia has a great article on Fourier Transformations. No need to explain it here. http://en.wikipedia.org/wiki/Fourier_transform