nsphrand

Circular, spherical, or n-sphere, uniformly distributed random numbers
35 Downloads
Updated 5 Jan 2019

View License

Uniformly distributed random numbers which fulfill the condition r_min < r_rand < r_max of an n-sphere
nsphrand([M N D]) or nsphrand(M,N,D) generates an M-by-N matrix of random numbers with the dimensionality D where D can for instance be one of the following:

D=1 => 0-sphere (line)
D=2 => 1-sphere (circle)
D=3 => 2-sphere (sphere)
etc

The components of the last dimension D is the vector of the sphere, which length can thus be interpreted as the radius.

r = nsphrand(...,'Rmin',rmin,'Rmax',rmax) sets the min and max radius for the generated random numbers (default 0 and 1).

Example:
r = nsphrand(10000, 1, 2, 'Rmin', 1, 'Rmax', 2)
plot(r(:,1),r(:,2),'.')

Cite As

Urban Eriksson (2024). nsphrand (https://www.mathworks.com/matlabcentral/fileexchange/69909-nsphrand), MATLAB Central File Exchange. Retrieved .

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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0