Random irrational number generator?

4.7k Views Asked by At

Is it possible to create a algorithm that will generate irrational numbers $0<x<1$ with a density that is uniform down a specified resolution?

Would such an algorithm be necessarily limited to irrational, non-transcendental numbers?

If we wanted to make it possible to generate transcendental numbers, how would our algorithm express them, and would they "outnumber" the non-transcendental numbers so much that all outputs would be almost surely transcendental?

How would we prove that the distribution was uniform down to our specified resolution?

4

There are 4 best solutions below

2
On

Let $n$ be the integer number of choices you want (the "resolution"). Let $Z$ be a random integer in the set $\{1, 2, ..., n\}$, equally likely over all options. Define $X = \pi Z/(4n)$. Then $X$ is the random irrational number you want.


I guess if you wanted it to have a density function, rather than a probability mass function, you could define $U$ as the standard uniform random variable over $(0,1)$ and define: $$ X = \left\{\begin{array}{ll} U & \mbox{ if $U$ is irrational} \\ \pi/4 & \mbox{ if $U$ is rational} \end{array}\right. $$ Then $U$ and $X$ have the same CDF and the same density.

0
On

pick a random rational number in (0,1) with the desired resolution.

pick your favourite trigonometric function and your favourite range for the arguments.

scale the rational to the range (such that (0,1) scales to your chosen range).

(!) compute the (transcendental) result of applying the function to the scaled argument

Accept the result with a probability inversely proportional to the density probability of the result from step (!).

Scale linearly to (0,1).


E.g.

Generate $a$ in (0,1).

Compute sin($a$).

Accept the result with probability cos($a$). (if result is rejected start from the beginning)

Divide result by sin($1$).

(the adjustment of probability can be done alternatively in the rational picking phase - accept $a$ with cos($a$) probability. The resolution of the picking process should/could be adjusted to yield the desired result resolution).

0
On

Under the hypothesis that $\pi$ is a normal number, you can shift the decimal expression of $\pi$: $$ a_0=\pi, \qquad a_{n+1} = \operatorname{frac}(10a_n) $$

Instead of $\pi$, you can also use the Champernowne constant, which is known to be normal.

0
On

Strictly speaking no, if it's an uniform distribution over an interval of $\mathbb R$ it's almost certain that the outcome could not be encoded (with whatever coding method you've choosen).

But if you as you say settle for "up to specified precision" then you've a situation where inclusion of irrationals doesn't make any difference. You just use a standard random number generator that generate random number with given precision. For example if you use two decimal precision you have to make sure that $0.01$ happens with $1\%$ probability (special cases are $0.00$ and $1.00$ that would have $0.5\%$ probability).