Simulation workspace
Choose a mode, distribution, parameters, seed, and output controls.
Quick presets
Formula used
Expected value
Variance and standard deviation
Sample statistics
Monte Carlo probability
Correlated normal variables
How to use this calculator
- Select a simulation, probability, sampling, multivariable, or fitting mode.
- Choose a discrete or continuous probability distribution.
- Enter valid parameters for the selected distribution.
- Set the number of observations and random seed.
- Open advanced settings for transformations and histogram bins.
- Run the calculation and review validation messages.
- Compare sample statistics against theoretical distribution properties.
- Inspect histograms, cumulative plots, Q-Q plots, and convergence.
- Download every generated value using CSV or JSON.
- Use browser printing to save a formatted PDF report.
Understanding random variable simulation
What is a random variable?
A random variable assigns numbers to uncertain outcomes. It converts chance events into measurable values. Probability distributions describe how those values behave.
A simulation generates possible observations from a selected distribution. Each generated value represents one possible outcome. Repeated outcomes reveal the distribution's overall pattern.
Discrete random variables
Discrete variables have countable possible values. Coin results and customer counts are common examples. Their probabilities are described using probability mass functions.
Bernoulli distributions model one success or failure. Binomial distributions model repeated independent Bernoulli trials. Poisson distributions model event counts during fixed exposure.
Geometric distributions model trials until the first success. Negative binomial distributions extend this idea further. Hypergeometric distributions sample without replacement from finite populations.
Continuous random variables
Continuous variables may take any value across an interval. Heights, waiting times, and lifetimes are common examples. Their probabilities are measured through areas under density curves.
Normal distributions model symmetric variation around a mean. Exponential distributions model memoryless waiting times. Weibull distributions commonly model reliability and component lifetimes.
Gamma distributions support flexible positive-valued shapes. Beta distributions model proportions between zero and one. Lognormal distributions model positive right-skewed measurements.
Random seeds and reproducibility
A random seed initializes the pseudorandom number generator. Reusing the same seed recreates the same sequence. This feature supports auditing, teaching, and experiment comparison.
Changing the seed creates another valid random sample. Different samples naturally produce different summary statistics. This variation is expected rather than erroneous.
Law of large numbers
The law of large numbers concerns long-run averages. Sample means usually approach theoretical expectations as samples increase. Small samples can remain noticeably different.
The running mean chart makes convergence visible. Early observations can move the average substantially. Later observations usually create smaller changes.
Central limit theorem
The central limit theorem concerns repeated sample statistics. Sample means often approach a normal distribution. This occurs even when the original population is not normal.
The sampling distribution mode demonstrates this behavior directly. It generates many independent samples from one population. The selected statistic is calculated for every sample.
Monte Carlo simulation
Monte Carlo methods estimate quantities through repeated random experiments. They support risk, reliability, finance, queues, and scientific models. Complex systems often become manageable through simulation.
Probability estimates use the proportion of matching outcomes. Expected payoffs use the average simulated payoff. Uncertainty shrinks when more independent simulations are used.
Custom discrete distributions
A custom discrete model uses user-defined outcomes and probabilities. Every value needs a matching nonnegative probability. The probability total should equal one.
Automatic normalization accepts proportional weights instead. For example, weights two, three, and five become probabilities. They convert into 0.2, 0.3, and 0.5.
Custom continuous distributions
A custom continuous model uses a density expression. The density must remain nonnegative within supplied bounds. A reliable upper density limit is also required.
This calculator uses rejection sampling for custom densities. Candidate values are generated uniformly across the bounds. Candidates are accepted according to relative density height.
Incorrect density maxima can invalidate rejection sampling. The calculator checks sampled points for obvious violations. Complex densities may require careful manual verification.
Transforming random variables
A transformation creates a new variable from each sample. Linear transformations shift or rescale generated values. Nonlinear transformations can change skewness and support.
Examples include 2*x+5, x^2, sqrt(x), and log(x). The safe expression parser restricts available operations. Arbitrary PHP code cannot execute through this field.
Multiple random variables
Many practical systems contain dependent random variables. Correlation measures their linear relationship. Covariance also reflects joint movement and measurement scales.
The multivariable mode creates paired normal variables. Users control both means and standard deviations. They also choose a target correlation coefficient.
Distribution fitting
Distribution fitting estimates parameters from observed data. This calculator compares normal, exponential, Poisson, and lognormal models. Availability depends on the imported values.
Log-likelihood measures model support for observed values. AIC adds a penalty for parameter count. BIC applies a stronger sample-size-sensitive complexity penalty.
Lower AIC and BIC values are preferred comparatively. They do not prove that a model is correct. Visual diagnostics and subject knowledge still matter.
Histograms and empirical distributions
A histogram groups observations into numeric intervals. Its appearance depends on the selected bin count. Too few bins can hide important structure.
The empirical cumulative distribution shows observed cumulative proportions. It does not assume a theoretical model. Each step corresponds to one or more observations.
Normal Q-Q plots
A Q-Q plot compares observed and normal theoretical quantiles. Roughly linear points suggest approximate normal behavior. Curved patterns may reveal skewness or heavy tails.
Q-Q plots are exploratory rather than definitive. Large datasets can reveal small harmless deviations. Small datasets may hide meaningful non-normal behavior.
Skewness and kurtosis
Skewness describes distribution asymmetry. Positive skewness indicates a longer right tail. Negative skewness indicates a longer left tail.
Excess kurtosis compares tail behavior against a normal model. A normal distribution has zero excess kurtosis. Positive values often suggest heavier tails.
Confidence intervals
The displayed confidence interval estimates uncertainty around the sample mean. It uses the sample standard error. A normal critical value supplies the interval multiplier.
This interval is an approximation. Strong dependence can make it misleading. Very heavy tails can also reduce reliability.
Simulation limits
Every simulation contains Monte Carlo sampling error. Rare events may need extremely large sample sizes. Extreme-tail estimates can remain unstable.
Large calculations also consume memory and processing time. This application enforces sample-size and batch limits. Those safeguards reduce server exhaustion risks.
Distribution guide
| Distribution | Typical purpose | Main parameters | Support |
|---|---|---|---|
| Bernoulli | One success or failure | Success probability | 0 and 1 |
| Binomial | Success count across trials | Trials and probability | 0 through n |
| Geometric | Trials until first success | Success probability | Positive integers |
| Negative binomial | Failures before required successes | Successes and probability | Nonnegative integers |
| Poisson | Event counts | Average event rate | Nonnegative integers |
| Hypergeometric | Sampling without replacement | Population, successes, draws | Feasible counts |
| Uniform | Equal density across an interval | Minimum and maximum | Finite interval |
| Normal | Symmetric measurements | Mean and standard deviation | All real numbers |
| Lognormal | Positive multiplicative data | Log-mean and log-SD | Positive values |
| Exponential | Waiting times | Rate | Nonnegative values |
| Gamma | Positive skewed durations | Shape and scale | Positive values |
| Beta | Probabilities and proportions | Two shape values | Zero through one |
| Weibull | Lifetime and reliability | Shape and scale | Nonnegative values |
| Chi-square | Variance-related statistics | Degrees of freedom | Nonnegative values |
| Student t | Heavy-tailed symmetric data | Degrees of freedom | All real numbers |
| F distribution | Variance ratios | Two degrees of freedom | Nonnegative values |
| Cauchy | Very heavy-tailed outcomes | Location and scale | All real numbers |
| Logistic | Symmetric heavier-tailed data | Location and scale | All real numbers |
| Laplace | Sharp central peak | Location and scale | All real numbers |
| Pareto | Heavy-tailed sizes and losses | Shape and minimum | Above minimum |
| Rayleigh | Vector magnitude models | Scale | Nonnegative values |
| Triangular | Bounded expert estimates | Minimum, mode, maximum | Finite interval |
Practical simulation examples
| Scenario | Suggested model | Example setup | Useful output |
|---|---|---|---|
| Coin toss | Bernoulli | p = 0.5 | Success proportion |
| Six-sided die | Discrete uniform | Minimum 1, maximum 6 | Frequency balance |
| Defects in production | Binomial | n = 100, p = 0.02 | Defect count risk |
| Customer arrivals | Poisson | λ = 8 hourly | Queue planning |
| First sale timing | Geometric | p = 0.1 | Required attempts |
| Call waiting time | Exponential | rate = 0.25 | Service thresholds |
| Exam scores | Normal | mean 75, SD 10 | Percentiles |
| Machine lifetime | Weibull | shape 1.8, scale 1000 | Failure probability |
| Claim severity | Lognormal | log-mean 7.2, log-SD 0.8 | Tail loss |
| Website conversions | Binomial | n = 1000, p = 0.04 | Conversion uncertainty |
| Portfolio shock | Student t | df = 5 | Heavy-tail stress |
| Market concentration | Pareto | shape 3, minimum 1 | Extreme-size behavior |
Frequently asked questions
Does the same seed always produce identical results?
Identical inputs and seeds reproduce the same PHP pseudorandom sequence. Different PHP implementations may occasionally behave differently. Save the full configuration with the seed.
How many observations should I generate?
Hundreds work for basic demonstrations. Thousands usually produce steadier descriptive statistics. Rare-event analysis may require far larger simulations.
Why does the sample mean differ from expectation?
Random samples naturally fluctuate around theoretical expectations. The difference is called sampling error. It generally becomes smaller with larger samples.
What is the difference between PMF and PDF?
A PMF assigns probability to discrete outcomes. A PDF assigns density across continuous values. Continuous point probabilities are normally zero.
Can custom probabilities be unnormalized weights?
Yes, enable automatic normalization. The calculator divides every weight by their total. Negative weights remain invalid.
How should I choose a custom density maximum?
Use a value at least as large as the density's highest point. A value too small invalidates rejection sampling. An overly large value reduces efficiency.
Why can the Cauchy mean look unstable?
The theoretical Cauchy mean does not exist. Sample averages can shift dramatically with extreme observations. Increasing sample size does not ensure convergence.
What does coefficient of variation mean?
It divides standard deviation by the absolute mean. It expresses relative variability across comparable positive-scale measurements. Values near zero means need caution.
What does a high positive skewness indicate?
It suggests a longer or heavier right tail. A few large values may strongly affect averages. Medians may better represent central tendency.
What does the Q-Q plot show?
It compares sample quantiles against normal theoretical quantiles. Straight patterns support approximate normality. Curvature reveals skewness or tail differences.
Can this replace specialist statistical software?
It is suitable for learning and exploratory simulation. Critical research requires validated specialist methods. Always verify assumptions and numerical accuracy.
Can I simulate correlated non-normal variables?
The included multivariable mode currently generates correlated normal variables. General copula support requires additional dependence models. The single-file architecture can be extended.
Why are only some probability formulas supported?
Closed forms are implemented for widely used distributions. Other cases may require numerical integration. Simulation can estimate unsupported probabilities.
How are CSV values protected?
Generated values are numeric and written using PHP CSV handling. Uploaded text is never copied directly into exported formula cells. This reduces spreadsheet injection risks.
What security protections are included?
The form uses a CSRF token. User output is HTML escaped. Custom mathematics uses a restricted parser instead of eval.