Member-only story

Python Pseudorandom Bytes

John Clark Craig
7 min readApr 15, 2021

A new algorithm for customizable, fast pseudorandom bytes that passes the tests with flying colors.

Photo by Ryunosuke Kikuno on Unsplash

Randomness is too important to leave to chance. Donald Knuth said that, and it’s a good mantra for programmers to adhere to. Generating pseudorandom numbers is a notoriously error prone challenge, and getting it right is extremely important.

Photo by Brett Jordan on Unsplash

The following very short pseudorandom byte generator Python class is easy to implement, and easy to analyze for any shortcomings, because it’s so simple compared to more complex algorithms. Most importantly, it passes standard tests of randomness, such as the software suite of tests provided by John Walker at Fourmilab in Switzerland.

I’ve implemented the algorithm as a Python class called Prb (Pseudo-random bytes) making it easy to import into your own projects. I’ll present the code first, and then explain how it works, and why it works as well as it does.

# prb.pyclass Prb:
def __init__(self, seed=""):
unique_seed = str(seed)+ "Customize here"
len_unique_seed = len(unique_seed)
self.p, self.q = 0, 0
self.buf = list(range(256))
for i in range(997)…

--

--

John Clark Craig
John Clark Craig

Written by John Clark Craig

Author, inventor, entrepreneur — passionate about alternate energy, technology, UFOs, and how Python programming can help you hack your life.

No responses yet