# The Blum-Blum-Shub Pseudorandom Generator

DevFeed: [The Blum-Blum-Shub Pseudorandom Generator](<https://devfeed.tech/articles/the-blum-blum-shub-pseudorandom-generator-40401.md>)

Original publisher: [Read original article](<https://www.jeremykun.com/2016/07/11/the-blum-blum-shub-pseudorandom-generator/>)

Published: 2016-07-11T08:00:54Z

Content type: tutorial

Language: en

Sources: [Jeremy Kun](<https://devfeed.tech/sources/jeremy-kun.md>)

Topics: [Randomizer](<https://devfeed.tech/topics/randomizer.md>), [Python](<https://devfeed.tech/topics/python.md>), [Algorithms](<https://devfeed.tech/topics/algorithms.md>), [Computer science](<https://devfeed.tech/topics/computer-science.md>), [implementation](<https://devfeed.tech/topics/implementation.md>)

Tags: [algorithm](<https://devfeed.tech/tags/algorithm.md>), [computer-science](<https://devfeed.tech/tags/computer-science.md>), [generator](<https://devfeed.tech/tags/generator.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [miller-rabin](<https://devfeed.tech/tags/miller-rabin.md>), [python](<https://devfeed.tech/tags/python.md>)

## AI overview

A tutorial on the Blum-Blum-Shub pseudorandom number generator, including a Python implementation, prime selection, quadratic residues, and the computational assumptions behind its unpredictability.

## Source excerpt

Problem: Design a random number generator that is computationally indistinguishable from a truly random number generator. Solution (in Python): note this solution uses the Miller-Rabin primality tester, though any primality test will do. See the github repository for the referenced implementation. from randomized.primality import probablyPrime import random def goodPrime(p): return p % 4 == 3 and probablyPrime(p, accuracy=100) def findGoodPrime(numBits=512): candidate = 1 while not goodPrime(candidate): candidate = random.getrandbits(numBits) return candidate def makeModulus(): return findGoodPrime() * findGoodPrime() def parity(n): return sum(int(x) for x in bin(n)[2:]) % 2 class BlumBlumShub(object): def __init__(self, seed=None): self.