Central Limit Theorem

April 11, 2026 ·

Giving this thing called Google Colab a go, and comparing them to Mathematica in terms of how they both embed on this website. Let's see how they work. The idea is to have widgets that showcase the Central Limit Theorem with configurable sample sizes.

Mathematica embeddings were messy so I took that off. Instead I took the Python notebook in Colab and hosted it on Hugging Face, then embedded it here. Cool concept, Colab. Anyway, the main idea I wanted to showcase is that it doesn't take a large sample size for things to start looking like a normal (bell) curve. A random sample starts to look like a bell curve at n of 2 or 3 even. That's pretty astonishing.

Here is the Python code I used, generated with the help of Google Gemini:

import gradio as gr
import numpy as np
import matplotlib.pyplot as plt

def plot_clt(dist_name, n):
    """Plot the distribution of sample averages to demonstrate the Central Limit Theorem."""
    # Generate 10,000 samples of size n for the selected distribution
    if dist_name == "Uniform (Flat)":
        samples = np.random.uniform(0, 1, (10000, n))
    elif dist_name == "Exponential (Skewed)":
        samples = np.random.exponential(1, (10000, n))
    else: 
        samples = np.random.chisquare(2, (10000, n))

    # Calculate the average across each sample
    averages = np.mean(samples, axis=1)

    # Plot the resulting distribution of averages
    fig, ax = plt.subplots(figsize=(8, 4.5))
    ax.hist(averages, bins=50, density=True, edgecolor='white')
    ax.set_title(f"Distribution of Averages (n={n})")
    return fig

with gr.Blocks() as demo:
    # Interface components
    dist = gr.Dropdown(["Uniform (Flat)", "Exponential (Skewed)", "Chi-Square (Skewed)"], value="Uniform (Flat)", label="Distribution")
    n = gr.Slider(minimum=1, maximum=30, step=1, value=1, label="Sample Size (n)")
    plot = gr.Plot()

    # Event listeners
    dist.change(plot_clt, [dist, n], plot)
    n.change(plot_clt, [dist, n], plot)
    demo.load(plot_clt, [dist, n], plot)

demo.launch()

~$1/comment: pay with card · pay with Ethereum