Skip to content
CoreSource checked

Box-Muller Transform

Generates normally distributed random values from uniform random values.

Quick Facts

Compact metadata for implementation and discovery.

Category
Randomness & Sampling
Difficulty
Beginner
Family
Random Variate Generation
Tier
Core
Status
Verified
Review
Source Checked
Sources
2
Formulas
1
Relationships
4
Code example
Ready
Visualization
Ready

Overview

The Box-Muller Transform converts two independent uniform samples into two independent standard normal samples.

Core Concepts

random drawsample selectionnormal samplerandom variate generationrandom sourcedistribution shape

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(1)

Average

O(1)

Worst

O(1)

Space

O(1)

When to Use

  • Use Box-Muller Transform when you need to transform uniform random samples.
  • Use it for simulation noise with inputs like two uniform random values.
  • Use it when randomization, representative samples, or controlled variation are needed.
  • Use it when the Random Variate Generation tradeoff is acceptable for the problem size.

When Not to Use

  • Avoid it when reproducibility, distribution quality, or sample independence cannot be verified.
  • Avoid it when the required output is not two normally distributed values.

What It Does

  • Transforms uniform random samples
  • Produces Gaussian random values

Use Cases

  • Simulation noise
  • Statistical sampling
  • Monte Carlo models

Inputs

  • Two uniform random values

Outputs

  • Two normally distributed values

Key Formulas (1)

Normal sample

z0 = √−2 · ln(u1) · cos(2·π·u2)
z0 = sqrt(-2 * ln(u1)) * cos(2*pi*u2)

Transforms two uniform random values into a standard normal sample.

Pseudocode

  1. 1.Draw two independent uniform values
  2. 2.Convert one value into a radius
  3. 3.Convert the other into an angle
  4. 4.Use sine and cosine to produce two normal samples

Canonical Example

Input
items = [A, B, C, D], seed = 7
Output
sampled or randomized result
Explanation
Box-Muller Transform: The algorithm uses controlled randomness to choose or generate values.

Implementation Notes

  • Keep the input contract explicit: Two uniform random values.
  • Separate the random number source from the algorithm so tests can use fixed seeds.
  • Separate the random source from the sampler so tests can use fixed seeds and distribution checks.

Common Pitfalls

  • Implementations must avoid taking the logarithm of zero.
  • Sampling from the wrong distribution can make the estimate look precise but biased.
  • Using biased random choices or forgetting to store the seed for reproducible runs.
  • Handle empty, invalid, and boundary inputs before trusting two normally distributed values.

Interactive Mechanism Walkthrough

Iterative Convergence & State Trajectory

Show uniform points mapped into a bell-shaped distribution.

Box-Muller Transform mechanism walkthrough step 1 of 4x₀x₁x₂x*
Step 1 of 4: Draw two independent uniform values
uniform-to-normal

Notes

Box-Muller Transform operates in O(1) time and O(1) space within the Random Variate Generation family. Key governing relation: z0 = sqrt(-2 * ln(u1)) * cos(2*pi*u2). Often compared with Linear Congruential Generator and Monte Carlo Simulation.

Sources (2)

What each reference supports for this entry.

Box-Muller Transform

Paper

Original reference for generating normal variates from uniform random variables.

Open source

Non-Uniform Random Variate Generation

Book

Random variate generation reference for Box-Muller Transform's distribution-sampling mechanism and acceptance or transform rules.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Box-Muller transforms uniform random values into Gaussian samples.

Box-Muller needs a source of uniform random values.

Tags

RandomnessSamplingNormal Distribution