File Exchange

image thumbnail

Uniform Spherical Distribution Generator

version (4.57 KB) by David
Generate uniformly random points within a sphere of dimension N


Updated 21 May 2018

View License

This function generates uniformly random points within a sphere of dimension N. It does this efficiently by inverting cumulative distribution functions, not by generating a uniform rectangular distribution and filtering away. This is particularly important for high dimensional spheres. In 6D for example, only one in twelve points generated in a 6D rectangle lies within the inner 6D sphere.
An example use-case of this function would be to initialize the positions and velocities of an ensemble of particles in three dimensions. In many physics simulations, it is common to perform such initializations independently for each dimension, which wastes processing power on uninteresting regions of phase-space near the corners of the 6D hypercube.

Cite As

David (2020). Uniform Spherical Distribution Generator (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (1)


This program is awesome. I really appreciate it.


Spelling Errors.

More appropriate title.

Prettier picture, more tags, better description.

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux