PHP Classes

CLT Simulator: Simulate the central limit theorem

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2026-07-06 (26 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
clt-simulator 1.0MIT/X Consortium ...8.2Algorithms, Graphics, Statistics, PHP 8
Description 

Author

This package can simulate the central limit theorem.

It provides a class that can take as parameters the number of samples and the sample size and generates an array of mean values and statistic values of the generated distribution with values of mean, standard deviation, minimum, and maximum value.

The package also provides a page that can show retrieve the generated values from the PHP script that runs on the server side and display the values on a canvas page element using the Chart.js JavaScript library.

Innovation Award
PHP Programming Innovation award nominee
July 2026
Nominee
Vote
The central limit theorem can be used to make predictions of values that make up part of samples that follow a normal distribution.

This package can generate mean statistic values following the central limit theorem and the generated values on a chart.

Manuel Lemos
Picture of Christos Drogidis
  Performance   Level  
Name: Christos Drogidis <contact>
Classes: 42 packages by
Country: Greece Greece
Innovation award
Innovation award
Nominee: 25x

Winner: 5x

Instructions

Example

<?php
require 'src/CLTSimulator.php';

use
Alexsoft\Statistics\CLT\CLTSimulator;

$sim = new CLTSimulator();

$numSamples = 10000; // Number of samples
$sampleSize = 30; // Size of each sample

$means = $sim->simulate($numSamples, $sampleSize);
$stats = $sim->statistics($means);

echo
"Central Limit Theorem Simulation\n";
echo
"Samples: $numSamples | Sample Size: $sampleSize\n\n";
echo
"Mean of all sample means: {$stats['mean']} (theoretical = 3.5)\n";
echo
"Standard deviation: {$stats['std_dev']}\n";
echo
"Range: {$stats['min']} - {$stats['max']}\n";
?>


Details

Central Limit Theorem (CLT) - PHP Simulator

The Central Limit Theorem (CLT) is one of the most fundamental principles in statistics. In simple terms: when we take many sample means from random samples, the distribution of those means tends to become normal (a bell curve), regardless of the shape of the original population.

This small project implements a CLT Simulator in PHP using a simple example: dice rolls ? sample means ? distribution of means.

Project Goals

  • Demonstrate how the CLT works in practice.
  • Simulate thousands of samples.
  • Compute basic statistics (mean, standard deviation, min, max).
  • Verify that sample means converge to the theoretical value 3.5 (the expected value of a fair die).

Structure

/public
    index.html
/src
    CLTSimulator.php
composer.json
example.php
README-EL.md
README.md
web-demo.php

How the CLT works here

  • Each die roll produces a value between 1-6 (uniform distribution).
  • We roll N dice ? compute the sample mean.
  • We repeat this process numSamples times.
  • The sample means form a bell-shaped curve centered around 3.5.
  • The larger the sample size, the more ?normal? the distribution becomes.

Usage Example

require 'src/CLTSimulator.php';

$sim = new CLTSimulator();

$numSamples = 10000;   // Number of samples
$sampleSize = 30;      // Size of each sample

$means = $sim->simulate($numSamples, $sampleSize);
$stats = $sim->statistics($means);

echo "Central Limit Theorem Simulation\n";
echo "Samples: $numSamples | Sample Size: $sampleSize\n\n";
echo "Mean of all sample means: {$stats['mean']} (theoretical = 3.5)\n";
echo "Standard deviation: {$stats['std_dev']}\n";
echo "Range: {$stats['min']} - {$stats['max']}\n";

Expected Results

With sampleSize = 30 and numSamples = 10000:

  • The mean should be close to 3.5
  • The standard deviation should be small
  • The range should converge around 2.5-4.5
  • The distribution of sample means should resemble a normal distribution

License

MIT License.

What does the CLT ultimately show?

That sample means are far more predictable than individual data points. Even a chaotic dataset becomes symmetric and orderly when viewed through the lens of averages.


  Files folder image Files (8)  
File Role Description
Files folder imagepublic (1 file)
Files folder imagesrc (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README-EL.md Doc. Documentation
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file web-demo.php Example App script

  Files folder image Files (8)  /  public  
File Role Description
  Accessible without login Plain text file index.html Data Chart Example

  Files folder image Files (8)  /  src  
File Role Description
  Plain text file CLTSimulator.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
Downloadclt-simulator-2026-07-06.zip
Downloadclt-simulator-2026-07-06.tar.gz
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Ascoos OS Download .zip .tar.gz Optional Optional
 Version Control Unique User Downloads  
 100%
Total:0
This week:0