Return to site

Linear feedback shift register random number generator

broken image

Here’s some PIC ASM code for our example LFSR: For some reason, LFSR taps are numbered starting on one, so take one off the tap position to get the bit that represents. I think you’ll have forgotten what the beginning sounded like by then!Īs an example, let’s take a 32-bit LFSR with four taps at positions 32, 30, 26, and 25.

broken image

If you output them as audio at 96KHz, the noise won’t repeat for an hour and a half. A 32-bit LFSR will produce a sequence of over 4 billion random bits, or 500 million random bytes. For synth and audio use, it is easily good enough. If the positions of the bits (the “taps”) are chosen carefully, this produces a maximal-length string of bits which is as damn near random as makes no odds to anyone other than mathematicians and cryptographers. In short, an LFSR takes a series of bits from a long shift register, XORs them together to come up with a resultant bit, shifts the register along one bit, and then sticks the new bit back into the beginning of the register. If you’re not really clear how an LFSR works, have a look at one of the many pages online (links below). I’ve used this method for creating noise generators and as an element in the random modulation generators I spent a long time developing for my Protowave synth. The linear feedback shift register is one of the most useful techniques for generating psuedo-random numbers.

broken image