> ## Content Index
> Fetch the complete content index at: https://starikov.co/llms.txt
> Use this file to discover other available public pages before exploring further.

# Calculating Euler's Number
- URL: https://starikov.co/calculating-eulers-number/
- Published: 2018-09-24T00:31:00.000Z
- Updated: 2026-06-09T23:01:24.000Z
- Author: Illya Starikov
- Tags: Mathematics, #u-color-bg-tag-accent, #u-color-text-dark

We are well aware of Euler’s famous number,

$$  
e = 2.71828182845  
$$

There are also quite a few ways of deriving Euler’s Number. There’s the Taylor expansion method:

$$  
e = \\sum \_{k=0} ^{\\infty} \\frac{1}{k!}  
$$

There is also the classical limit form:

$$  
e = \\lim\_{n \\rightarrow \\infty} \\left( 1 + \\frac{1}{n} \\right)^n  
$$

Then there is another. Let \\(R\\) be a random number generated between \\(\[0, 1\]\\), inclusive. Then \\(e\\) is the average of the number of \\(R\\)s it takes to sum greater than \\(1\\).

With more rigor, for uniform \\((0,\\, 1)\\) random independent variables \\(R\_1\\), \\(R\_2\\), \\(\\ldots\\), \\(R\_n\\),

$$  
N = \\min \\left\\{n: \\sum\_{k=1}^n R\_k > 1 \\right\\}  
$$

where

$$e = \\text{Average}(n)$$

The proof can be found [here](https://math.stackexchange.com/questions/111314/choose-a-random-number-between-0-and-1-and-record-its-value-keep-doing-it-until?ref=starikov.co), but it’s pretty math-heavy. Instead, an easier method is to write a program to verify for large enough \\(n\\).

| n          | Sum Solution | Limit Solution | Random Uniform Variable |
| ---------- | ------------ | -------------- | ----------------------- |
| 1          | 1            | 2              | 2                       |
| 10         | 1.7182818011 | 2.5937424601   | 2.5                     |
| 100        | 1.7182818284 | 2.7048138294   | 2.69                    |
| 1000       | 1.7182818284 | 2.7169239322   | 2.717                   |
| 10000      |              | 2.7181459268   | 2.7242                  |
| 100000     |              | 2.7182682371   | 2.71643                 |
| 1000000    |              | 2.7182804690   | 2.71961                 |
| 10000000   |              | 2.7182816941   | 2.7182017               |
| 100000000  |              | 2.7182817983   | 2.71818689              |
| 1000000000 |              | 2.7182820520   | 2.718250315             |

![](https://starikov.co/content/images/2025/11/calculating_eulers_number.png)

## Source Code

```python
def e_sum(upper_bound):
	if upper_bound < 1:
		return 0

	return Decimal(1.0) / Decimal(math.factorial(upper_bound)) + \
	       Decimal(e_sum(upper_bound - 1))

def e_limit(n):
	return Decimal((1 + 1.0 / float(n))**n)

def find_greater_than_one(value=0, attempts=0):
	if value <= 1:
		return find_greater_than_one(value + random.uniform(0, 1), attempts + 1)

	return attempts

```