If you want to generate 1-32 bit white noise programmatically on a 32-bit microcontroller, then I can warmly recommend using the 32 high bits of the
Xorshift 64* pseudorandom number generator:
#include <stdint.h>
uint64_t prng_state;
uint32_t prng_u32(void)
{
uint64_t x = prng_state;
x ^= x >> 12;
x ^= x << 25;
x ^= x >> 27;
prng_state = x;
return (x * UINT64_C(2685821657736338717)) >> 32;
}
You initialize
prng_state to any value except all zero; 1 to 18,446,744,073,709,551,615 inclusive.
The output of
prng_u32() passes all randomness tests in the BigCrush test suite of the
TestU01 framework. In the numeric computation world, it is considered the "gold standard" for numerical (pseudo-)randomness. It even beats Mersenne Twister (MT19937) in both speed and 'randomness'.
The period is 2
64-1; even if you emit 2
32 = 4,294,967,296 values per second, it'll take over 136 years before it repeats the same sequence.
One of the microcontroller dev boards I have,
Teensy LC, has a 12-bit hardware DAC, and the above can be trivially modified to return the high 36 bits (by changing the last line to
)) >> 28; and the return value to uint64_t), in which case every call would produce three samples. I expect an interleaved version to be able to generate 100k - 1M samples/sec, perhaps 100,000 - 300,000 if using DMA to ensure minimal jitter between samples (which might otherwise cause noticeable 'coloring' in the generated spectrum).
I could write a test sketch (it's programmed in the Arduino environment using
Teensyduino), but unfortunately I don't have a real oscilloscope or frequency analyzer (nor access to one right now) to analyze and quantify the output.