## FANDOM

573 Pages

Bach's algorithm is a probabilistic polynomial time algorithm for generating random numbers along with their factorization, named after its discoverer, Eric Bach. It is of interest because no algorithm is known that efficiently factors numbers, so the straightforward method, namely generating a random number and then factoring it, is impractical.

The algorithm performs, in expectation, O(log n) primality tests.

A simpler, but less efficient algorithm (performing, in expectation, O(log2 n) primality tests), is known and is due to Adam Kalai

## Overview Edit

Bach's algorithm produces a number x uniformly at random between a given limit N and N/2, specifically $\frac{N}{2} < x \le N$, along with its factorization. It does this by picking a prime number p and an exponent a such that $p^a \le N$, according to a certain distribution. Bach's algorithm is then recursively applied to generate a number y uniformly at random between M and M/2, where $M = \frac{N}{p^a}$, along with the factorization of y. It then sets $x = p^{a}y$, and appends $p^a$ to the factorization of y to produce the factorization of x. This gives x which logarithmic distribution over the desired range; rejection sampling is then used to get a uniform distribution.

## Edit

Community content is available under CC-BY-SA unless otherwise noted.