I was wondering if anyone was familiar with any popular audio-based algorithms / literature / research for deriving or generating random numbers through audio?
Given that most random number generators generate random numbers partly through the multiplication / division of large static numbers, I was wondering if anyone knew of random number generators that used audio instead (especially using 2 or more audio sources).
For example, let's say we were tasked with calculating a random odd number (preferably large).
One hypothetical way of calculating this number would be to record 1 minute of room tone / room noise in our living room (as a mono audio source).
Then recorded another 1 minute of room tone / room noise in our garage (as a mono audio source).
If we were to combine both mono audio signals into a stereo track:
...and then process the stereo signal through a Sound Field scope (which displays phase balance issues in a stereo track):
...we might be able to use the plotted data to derive the random odd number (ex. choosing the furthest prime sample point from the origin).
Note: The reason for my use of room tone / room noise is due to its random nature. That said, there may be other sound sources that are more random - but I haven't yet encountered any that can be easily acquired / recorded and that aren't generated algorithmically (ex. using a random number generator).
If there aren't well established ways in audio / DSP, but you yourself have a good idea, I'd be interested in hearing it.
That seams to be an unreasonable effort to me - if I were to use audio as a source for random numbers, I'd take one audio sample (as in one sample: T = 1/44100), use it as a seed for a standard random number generator and derive my number from there...
Besides, the method you suggest above will produce numbers that are random (meaning: "no" two numbers are the same and the exact amount cannot be predicted) but the probability distribution will be pretty narrow, I think...
if I were to use audio as a source for random numbers, I'd take one audio sample (as in one sample: T = 1/44100), use it as a seed for a standard random number generator and derive my number from there...
That's an awful way to generate a seed for random numbers. Even if you consider it as equally-distributed between its extremes, how many bits are you talking about? 16? 18? 20?
If you're trying to generate a pseudorandom number stream, the number of bits in the seed dictates the number of distinct output streams, so a 20-bit seed can only produce about 1 million different output streams.
Well-designed systems gather entropy from samples of real-world data and use combining functions (e.g. a hash function) to generate random seeds with much higher bit counts (128, 256, 512) depending on the required seed size; cryptographic applications require more bits but even non-cryptographic applications should probably use at least a 64 bit seed.
I wouldn't use audio as a source in the first place - why would I - I just said I wouldn't go through all of the hassle described above just to get a number that may be random, but pretty well predictable in amplitude.
Using one sample as a seed for a random stream will get me something closer to my vague definition of random (unpredictable and somewhat uniformely distributed) than the initial idea.
Still your remark is correct, of course - for 16bit audio there are only 2^16 different possible seeds: Then, how about using the first sample as an index k, take the sample at the index position y(k) as the 16LSBs, take the following sample as the next index k = y(k+1), take the sample at the second index position as bit17 through 32 and so on.
You might want to add some 16bit constant modulo 2^16 to the indices to avoid getting zero indices (audio tends to start at zero amplitude - at least downmixed audio).
That said, do you see any issue with using combining functions, so that a 24 or 32 bit number is combined multiple times over to create a 256, 512, 1024 etc bit number?
For my current purposes, as long as the number being generated is somewhat random (as very few things if any are truly random) without being generated algorithmically, I'm okay.
Unfortunately I can't use a random number generator.
I'm working under the assumption that all random number generators are suspect (ex. tampered by the NSA to produce numbers which aren't so random).
So I must use something that is not generated via some algorithm (which could be tampered with).
As for your comment, though the following gives me hope:
"Besides, the method you suggest above will produce numbers that are
random (meaning: "no" two numbers are the same and the exact amount
cannot be predicted)"
...would you be able to expand upon the following statement:
"...but the probability distribution will be pretty narrow, I think..."
Can I assume what you're saying is that, though my numbers will be random, the distribution of those numbers will not be even?
For example, let's say I was choosing a random number from 1 - 10 using my algorithm. Are you saying that the distribution of those random numbers would be more heavily weighted towards certain numbers?Thank you,
"For example, let's say I was choosing a random number from 1 - 10 using my algorithm. Are you saying that the distribution of those random numbers would be more heavily weighted towards certain numbers?"
The audio you mention will probably not have sufficient randomness to be useful for random number generation. As you said it will probably have tones and various man-made noises, which obviously have high correlation.
A common method of generation truly random numbers is to sample the thermal noise voltage on a resistor. This noise is white and Gaussian distributed, and the energy per Hz increases linearly with temperature. The reason for these characteristics are well understood (first explained in a paper by Nyquist in 1928).
There is little reason to suspect similar characteristics in background noise in a typical room.
Thank you very much for your response.
This may sound like a stupid question, but is there an easy way to sample the thermal noise voltage on a resistor? In other words, do I need to use expensive scopes to properly sample the thermal noise, or will a cheap device suffice?
Furthermore, will a cheap device provide me the necessary thermal resolution / data accuracy needed, or will I need to use more expensive equipment?
The reason for my question is that I was using ambient noise due to the simplicity in acquiring such data. In other words, with a simple computer and USB microphone, we can acquire all the data we need.
However, sampling the thermal noise voltage on a resistor doesn't seem like something that's easy to acquire, unless you've got a bunch of specialized equipment lying around.
Part of the restrictions on the project I'm working on, specify that acquisition of this random data not require the use of uncommon household items.
So using something like a computer, isn't a problem. Even a microphone is easy to come by, but sampling the thermal noise of a resistor doesn't seem as easy (though I may be able to figure out how to use something like an Arduino or Raspberry Pi with an on-board thermal resistor).
If you were asked to devise the simplest way at sampling the thermal noise voltage of a resistor (preferably using common household items / equipment), how would you do it?
Also, does the paper by Nyquist speak about the randomness of this method?
Furthermore, is there any mathematical proof backing up his claims (as the data produced by his method may not actually be that random)?
Lastly, would you happen to know where I could find the paper (by Nyquist)?
Thank you very much for all your help,
I see that quite a few people already answered you, but here are my 2 cents.
First, if your project is to produce random noise, don't allow people to convince you that pseudorandom number generators do this. There is an important philosophical different and a practical difference. The philosophical difference is that all PRG are based on chaotic but completely deterministic mechanisms. This leads to the practical difference. For example - if you are using the random values to create a one-time pad in order to create a provably unbreakable encryption, then a PRG will just not do.
Now to your question. Nyquist's paper appeared in Physical Review vol 32 (1928). The important result is that the noise variance is proporational to the temperature times the resistance, with the constant being simply 4 times the Boltzman constant. So, at room temperature (about 300 Kelvin) a 10 KiloOhm resistor will have a noise voltage of about 1.3 microvolt if you lowpass filter to 10 KHz bandwidth. A 120 dB preamp, like those used for hearing aids, will bring this up to 1.3 volts.
Thermal noise is completely random and white, and so theoretically unpredictable. Of course, once you lowpass filter it you introduce correlations between consecutive values, but it is easy to see how much correlation exists and derive theoretically statistically independent values.
There are other mechanisms that could be used to derive truly random values. For example, there is shot noise on the current of a resistor - but that is harder to measure and the values are Poisson distributed values.
In practice, there are methods of creating random values using digital components. For example, people use metastability and race conditions to generate random numbers in FPGAs.
I had one last question I was hoping I could ask you.
Before asking my question, I first wanted to thank you for all your help. Your observations and insights have significantly altered the development and direction of my project, but in a good way.
My question is this: You previously mentioned Gaussian and Poisson random number distributions when using thermal resistor noise voltage sampling and resistor shot noise sampling.
Are you familiar with any other random number distributions (using sampling techniques like the ones previously mentioned)?
For instance, are you familiar with techniques for generating evenly distributed random numbers?
Gaussian (and possibly Poisson) distributed random numbers will be very helpful for my project, but I will also need something that is more evenly distributed.
I ask this question as it would be very helpful to know the major types of random number distributions (when using sampling techniques like the ones previously mentioned).
Obviously one can alter a sampling technique to generate almost any kind of random number distribution. But I'm looking for well established / understood random number generation distributions (using natural phenomena like resistor noise voltage sampling).
Off hand, all the physical sources of noise that I can think of (the ones already mentioned, and radioactive decay, avalanche diode noise, etc.) are either Gaussian or Poisson. Some may have superposed (semi-)periodic components (such as the wander of frequency references).
This is very reasonable. You wouldn't expect a physical source to be truly uniform - as that would imply infinite range. Of course, a Gaussian distribution is approximately uniform over a small enough range near its maximum.
One way of getting a uniform distribution without exploiting the mathematical transformations you refer to, is to generate single bits by thresholding some random phenomenon, and then filling a register with these bits. This is also manipulation (and requires any more samples of the physical phenomenon), but is somewhat more direct.
Understood, and good to know.
Once again, I can't thank you enough for all your help.
This paper claims to produce random numbers of quantum origin using a regular smart phone camera : - https://journals.aps.org/prx/abstract/10.1103/Phys...
Assuming the paper withstands peer review (as it seems pretty new - circa 2014), it would be incredibly helpful.
Once again, a big thanks.
I have never made any serious research in that field, so I just give my opinion after a transverse reading of your proposal.
I would not use an audio signal coming from a room as random number source. The problem I see is that you assume that the noise from your room is random by default, and I think that is assumption is wrong. This could be true if there absolutely no other noise made in the room, but what you will capture will the sum of the background noise and "man made" noises which are much more louder by definition.
And the man-made noise are most of the time predictive by nature, which counters the effect you look for. Moreover, if you want to use the background, you will need to have a an high gain capture system. If there is any other noise made (people talking for example), it will cover the background noise source and will saturate the input stage. And if you want to avoid saturation, you will need to lower the gain which will make background almost silent and limit the range of random values you can get, which makes this "less random"
So personnally, I would not use this as a random number source.
Thank you for your input.
Out of curiosity, why would capturing other noises in a room be a problem?
For instance, let's say we're recording 1 minute of room tone, and during the recording we have the air conditioner on and are on our computer typing on our keyboard.
Not only would we be capturing the room tone, but also:
1. The hum of the AC.
2. The hum of the PC fans.
3. Any extra PC noises (ex. hard drive spinning).
4. Typing on the keyboard.
All of these captured sounds would seem to create something that is more random than just the room tone, in the sense that it would be harder for someone to duplicate / anticipate.
So I'm a little confused why this would be a problem when capturing the room tone.
Furthermore, though man made noises can be predictive (ex. the ticking of a clock), things like typing on a keyboard, or the squeaks of a chair (that someone is sitting in), aren't (in my opinion).
It would seem to me that these sort of extra random noises would be a good thing. That said, you do bring up a good point when it comes to these extra noises drowning out the room tone.
Out of curiosity, would using something like a compressor help in alleviating these issues?
In other words, if we set the threshold of our compressor to a portion of our room tone recording where no other extra noises are present, and then set a hard compression ratio (ex. 10:1 or 100:1), we could greatly squash any extra random noises (ex. typing on a keyboard) above our room tone.
Or if that doesn't work, we can use make-up gain (on the compressor) to boost the room tone so that it equals the amplitude of our extra noises.
the noises you are describing as random are most of the time highly predictive, because they have a fixed frequency. They appear to our ears as noises, but if you look to their spectrum, you will see fixed frequencies.
Eg : hum of the fan = made by 50Hz or 60Hz mains frequency
Now, as I said, I never made any research in that particular field, so maybe it can work. I just say that I think that the sources you are describing can't be described as random, imho
I believe I understand what you mean.
I assume what you're saying is that something like a chair squeaking, AC hum or PC fan spinning won't be random in its frequency distribution.
Instead it will have a fixed (aka dominant) frequency.
Whereas something like noise (ex. white or pink noise), won't have a fixed frequency.
So it sounds like when you refer to random noise, you're referring to something that has an even random frequency distribution, correct?
I'm a little confused. You seem to NOT want to use a random number generator and then refer to using a seed for a random number generator. So, which is it?
I assume you're referring to another poster.
As for myself, I'm looking at generating random data / numbers without using a random number generator / algorithm of any sort (as algorithms tend to be suspect, whereas natural phenomena isn't as much).
That said, from some of the comments in this thread, it seems that my approach is neither random enough nor evenly distributed (number-wise) to be of any serious use.
Out of curiosity, would you happen to have any ideas?
Somehow you are going to sample the room noise. What if you simply disconnect (or short out) the microphone and amplify the noise of your amplifiers, etc. until you get enough amplitude to make sense in your application.
Of course, one would caution that the resulting "signal" should be tested for spectral characteristics (which you'd want to not be evident except for whiteness). You probably don't care much about the difference between "white" and "pink" for this application. But that depends on your end objective.
It's certainly worth a try....
Unfortunately I'm not certain I understand what you mean.
In reference to shorting the microphone, can I assume what you mean is that we short the microphone while the mic is connected to a set of amplifiers, in order to record the sound the microphone makes when being physically disconnected from the amplifiers?
In other words, generating a sound similar to the sound you get when unplugging a guitar from a powered guitar amplifier (ex. the loud buzzing / popping sound the amp makes when the guitar is disconnected)?
As for the spectral characteristics we wouldn't want, can you provide a simple example of such a characteristic (which we wouldn't want)?
I'm not talking about a transient caused by connecting or disconnecting. I meant that the microphone should be disabled or not there at all. Normally, the input to the sampler can be represented as:
A2*(A1*(A0*(So + N0)+N1)+N2)
Where So is the microphone output and N0 is the microphone or microphone and mic preamp electrical noise - maybe white noise. These are amplified by A0.
Where N1 is the noise of the following amplification stage. This and the preceding stages input are amplified by A1.
Where N2 is the noise of the following amplification stage. This and the preceding stages input are amplified by A2.
... and so on.
So, if you zero So by disconnecting the mic and by leaving open or shorting the mic input to the amps, you get:
A0*A1*A2*N0 + A1*A2*N1 + A2*N2
It's reasonable to believe that A0*A1*A2*N0 is the largest term but if the A0 amplifier is particularly low noise (which it may be) then other terms may dominate. No matter really.... Adjust A2 to get the highest output. Adjust A1 similarly until you get to a point where the noise output isn't terribly saturated (limited) by either the amps or the sampling word length.
This is easy to try and relies on the electrical noise of things like resistors, etc. If there's no pickup due to EMI then it *should* be white or maybe pink.
White noise has flat spectral character. In other words, the noise level per sqrtHz is equal.
Pink noise decays with frequency so that level per sqrtHz goes down with frequency.
Either way, this is a better source of random noise and, thus, random samples going through A/D yielding random numbers.
You can test the randomness of the numbers by doing a histogram of all the possible numbers. If it peaks at the maxima then there's too much saturation.
In summary, get rid of the mic and crank up the amps.
bits = ( sample >> 3 ) & 15;
You can easily accumulate these bits into a single value by shifting and ORing several together. The result should be a uniformly random value.
It that is not good enough, you can combine several of these values in some math operations and harvest a subset of the bits from the result. This is PRGish, but you are "reseeding" it every sample.
Random numbers are a huge field of study, especially as they relate to cryptography which is sounds like your application may be by the reference to "No Such Agency".
Hope this helps.
Thank you very much for your help.
I should have thought about using a similar technique as the one you described.
That being said, is there any research / literature that backs up your suggestion?
I only ask as I'm worried that just choosing an arbitrary bit length somewhere towards the middle of a bit string, won't be random enough.
In other words, is there some literature that provides some sort of guidance like:
Assuming a bit stream of N bits, a sufficiently random number is the middle 1/3 of the bit stream.
It isn't a case of the middle is the most random as your graphic depicts. You want to avoid the low order bits because of the potential non randomness introduced by dithering performed by the ADC process. You want to avoid the high order bits because they are going to be weighted towards zero. Therefore you want the highest order bit you use to be quite low compared to your expected sound level. To be super safe you could grab just the two bits at positions 2 and 3.
Something else you should do is skip a few sound samples between each one you use. This should ensure that you won't get any close to repeat values for slowly moving signals. Using a random skip size would be better.
You can also test each sample to see that it is significantly larger than the highest order bit you are grabbing. This will ensure you aren't getting any zero bias in your high order bits of your harvest zone.
Hope this helps.
Here's one paper. A little more searching on terms you find within it should find you some more.
A big thank you for all your help.