Function Repository Resource:

# RandomUnitVector

Generate random vectors in any dimension of unit length

Contributed by: Sander Huisman
 ResourceFunction["RandomUnitVector"][d] generates a d-dimensional unit vector. ResourceFunction["RandomUnitVector"][d,n] generates n d-dimensional unit vectors. ResourceFunction["RandomUnitVector"][d,{n1,n2,n3,…}] generates an n1⨯n2⨯n3… array of d-dimensional unit vectors.

## Details

ResourceFunction["RandomUnitVector"][] generates a single two-dimensional unit vector.

## Examples

### Basic Examples (2)

Generate a two-dimensional unit vector:

 In[1]:=
 Out[1]=

Generate 5 random three-dimensional unit vectors:

 In[2]:=
 Out[2]=

### Scope (3)

Generate a 4×6 array of 3D unit vectors:

 In[3]:=
 Out[3]=

Check the dimensions:

 In[4]:=
 Out[4]=

Check the magnitudes:

 In[5]:=
 Out[5]=

### Applications (2)

Generate a random points on a circle:

 In[6]:=
 Out[6]=

Generate some random points on a sphere and compare with built-in functionality:

 In[7]:=
 Out[7]=

### Properties and Relations (1)

Check the uniformity of the unit vectors:

 In[8]:=
 Out[8]=

### Neat Examples (2)

Perform a 2D random walk with steps of unit length:

 In[9]:=
 Out[9]=

Perform a 3D random walk with steps of unit length:

 In[10]:=
 Out[10]=

SHuisman

## Version History

• 1.0.0 – 17 May 2022