CC Blog • Quick Bits • Resources

Pseudorandom Bit Sequences

Written by Andrew Levido

Its relatively common in electronics design to require a well-defined source of randomness. One popular approach is to generate a random stream of digital ones and zeros. Like an automated coin-tossing machine, at any given point in the sequence there should be a 50% chance that the next digit in the sequence will be a 1 and a 50% chance it will be a zero.

It turns out to be relatively easy to generate very nearly perfectly random sequences with a quite simple circuit as shown in Figure 1. Here an m-bit shift register is clocked at a fixed-frequency, f0. The input of the shift register is fed from an exclusive-or combination of the last bit (the mth) and another bit (the nth). This is known as a linear feedback shift register (LFSR) circuit.

Figure 1
A shift register and an exclusive-or gate is all that is required to generate a pseudorandom bit sequence. The output bitstream exhibits very good randomness, particularly for longer sequences (say 16 bits or more).

The simplest possible example, shown in Figure 2, has a three-bit shift register with taps at n = 2 and m = 3. In the table on the right, we start with the shift register loaded with all ones (although we could start anywhere except for all zeros), and step through the circuit state each clock cycle. You can see that all of the possible  three-bit binary numbers except zero appear once in the output which repeats every 7 cycles.

Figure 2
The simplest possible LFSR has just three shift register stages. The truth table shows that the circuit steps through 7 of the 8 possible combinations (all-zeros is not possible). The repeat time increases exponentially with additional shift register stages.

The all zero state is not allowed since the circuit will remain “stuck” in this state indefinitely.

In general terms, the number of possible states for an m-bit shift register is 2m. Since we can’t have all zeros, the largest number of states we can iterate through is  2m – 1. It turns out that if you choose m and n correctly you can make a “maximal length” LFSR that exercises all these states for any value of m above 3. For some cases (for example when m is a multiple of 8 ) you need three taps instead of two.

So how random is the output? It does not matter which of the shift register stages we designate to be the output, since the data propagates through each stage. In each cycle there will be one more 1 than there are 0s, since the all-zero result is omitted. The “runs” of 1s and 0s are distributed as you would expect – half will be runs on one, one quarter will be runs of two, one eighth will be runs of three etc, indicating the probability of a 1 or 0 does not depend on past behaviour. Instead, the outcome of each “toss” is independent of prior results, just like a fair coin.

While the trivial example of Figure 2 might not seem too random, using longer sequences makes a big difference. For example, a 32-bit shift register clocked at 1MHz will repeat only after 70 minutes or so. The number of 1s during this period will be 2,147, 483, 648 and the number of 0s will be  2,147, 483, 647. That’s pretty close to 50:50, I think. Using a 48-bit shift register extends this cycle to almost 9 years! It is not usually necessary to go beyond 32 bits in practice.

Pseudorandom bit streams are very useful in generating test sequences in digital communication test equipment such as Bit Error Rate testers (BERTs) and in generating Eye diagrams. They are also used for bit scrambling such as in Ethernet or CDMA.

These latter applications take advantage of the (somewhat contradictory sounding) fact that the randomness is deterministic. That is to say the scrambling of a transmission by means of an LFSR can be undone by a similar LFSR at the reception end, provided the two are synchronised somehow. The pseudo-random scrambling ensures the signal across the physical link has plenty of 1 to 0 and 0 to 1 transitions – useful for AC coupling for example.

Another interesting application of pseudo-random bit sequences is in the generation of analog noise. You can of course use an analog noise source such as a diode junction and amplifier to produce a noise signal. This works but is sensitive to picking up unwanted interference – for example mains hum – that undoes the “randomness” of the noise.

The noise power spectrum generated by a LFSR circuit extends from the repeat frequency of the cycle f0/(2m – 1) up to frequencies well above the clock frequency f0. Adding some circuitry to make the LFSR’s output swing symmetric about zero volts and adding a simple RC low-pass filter is enough to produce a reliable and stable noise source. Figure 3 shows an example of how this might be done.  The low-pass filter corner frequency should be below about 15% of f0for a flat power spectrum.

Figure 3
This diagram shows how to generate an analogue noise source using a LFSR pseudorandom bit sequence generator. The bitstream is first shifted to be symmetrical about zero volts and then filtered – in this case with a simple RC filter.

It is beyond the scope of this article, but it is relatively easy to calculate the noise voltage density at the output of the level shifter to be V √(2/f0) expressed in volts per √Hz. The noise bandwidth of the low pass filter will then let you determine the rms value of the output noise.

Bibliography

3030622440586. “PRBS (Pseudo-Random Binary Sequence).” Kurt Tomlinson’s Blog, February 4, 2015. https://blog.kurttomlinson.com/posts/prbs-pseudo-random-binary-sequence.

Horowitz, Paul, and Winfield Hill. The Art of Electronics. Third edition, 11th printing, with Corrections. Cambridge New York, NY: Cambridge University Press, 2017.

Keep up-to-date with our FREE Weekly Newsletter!

Don't miss out on upcoming issues of Circuit Cellar.


Note: We’ve made the Dec 2022 issue of Circuit Cellar available as a free sample issue. In it, you’ll find a rich variety of the kinds of articles and information that exemplify a typical issue of the current magazine.

Would you like to write for Circuit Cellar? We are always accepting articles/posts from the technical community. Get in touch with us and let's discuss your ideas.

Sponsor this Article
+ posts

Andrew Levido (andrew.levido@gmail.com) earned a bachelor’s degree in Electrical Engineering in Sydney, Australia, in 1986. He worked for several years in R&D for power electronics and telecommunication companies before moving into management roles. Andrew has maintained a hands-on interest in electronics, particularly embedded systems, power electronics, and control theory in his free time. Over the years he has written a number of articles for various electronics publications and occasionally provides consulting services as time allows.

Supporting Companies

Upcoming Events


Copyright © KCK Media Corp.
All Rights Reserved

Copyright © 2026 KCK Media Corp.

Pseudorandom Bit Sequences

by Andrew Levido time to read: 4 min