Connect via MCP →

Enter Calculation

Formula

Show calculation steps (1)
  1. Chi-Squared via Gamma Relation (general v)

    Chi-Squared via Gamma Relation (general v): Chi-Squared Distribution Random Number Generator

    For non-integer v, values are drawn from the chi-squared density with v degrees of freedom; the theoretical mean is v and variance is 2v.

Advertisement

Results

Sample mean of generated values
2.6906
expected mean = v = 3

Random values from chi-squared(v = 3)

  1. 1.660307359
  2. 0.7121040726
  3. 1.182711505
  4. 3.380309316
  5. 8.038491730
  6. 3.443283765
  7. 1.128511959
  8. 1.475106494
  9. 4.125745582
  10. 1.759675269
Count generated 10
Theoretical mean 3
Theoretical variance 6
Theoretical SD 2.4495
Sample mean 2.6906

What this tool does

This generator produces a list of pseudo-random numbers drawn from a chi-squared distribution with a chosen number of degrees of freedom, written \(v\) (the Greek letter nu). The chi-squared distribution is fundamental in statistics: it describes the sum of squared independent standard-normal variables and underlies chi-squared goodness-of-fit tests, variance estimation, and confidence intervals.

How to use it

Enter the degrees of freedom \(v\) (any positive real number, default 3), the number of random values you want (1 to 1000, default 10), and pick how many significant digits each value should display. Click calculate to get a fresh sample. Because the generator is random, every run gives different numbers, but the theoretical mean (\(v\)), variance (\(2v\)) and standard deviation (\(\sqrt{2v}\)) shown alongside are fixed and let you sanity-check the sample.

The formula explained

The chi-squared density is $$f(x,v) = \frac{x^{v/2-1}\, e^{-x/2}}{2^{v/2}\,\Gamma(v/2)}, \quad x \geq 0.$$ To draw samples we use the fact that a chi-squared(\(v\)) variable equals 2 times a Gamma variable with shape \(v/2\) and scale 1. For integer \(v\) we use the simpler identity $$X = Z_1^2 + Z_2^2 + \cdots + Z_v^2,$$ where each \(Z\) is a standard normal generated by the Box-Muller transform. For non-integer \(v\) we use the Marsaglia-Tsang gamma method and then multiply by 2.

Advertisement
Chi-squared probability density curves for several degrees of freedom
Chi-squared density curves for increasing degrees of freedom \(v\), shifting right and flattening.

Worked example

With \(v = 3\) and count = 10, each value is the sum of three squared standard normals. A representative sample might be 1.842, 4.317, 0.526, 2.991, 6.083, 1.205, 3.778, 0.914, 5.460, 2.337. Their average is about 2.945, close to the theoretical mean of 3. Every value is non-negative, as required.

Histogram of generated samples overlaid with the theoretical chi-squared curve
A histogram of generated values closely follows the theoretical chi-squared density.

FAQ

Why do my numbers change each time? The generator uses a random source, so each run produces an independent sample. The theoretical statistics stay the same.

Can \(v\) be a decimal? Yes. Any \(v\) greater than 0 is valid; the tool uses the gamma method for non-integer values.

What if I ask for more than 1000 values? The count is clamped to the allowed range of 1 to 1000.

Last updated: