# Global/VectorRand

From Garry's Mod

## Contents |

## Replacement

# Examples

## Example

The following replacement for VectorRand will produce uniformly distributed unit vectors (directions)

function VectorRandDir() local theta = math.Rand(0,2*math.pi) local radius = math.sqrt(math.Rand(0,1)) return Vector(radius * math.cos(theta), radius * math.sin(theta), math.sqrt(1-radius*radius) * (math.random(0,1)*2-1)) end

## Additional Notes

- This will not return unit vectors (Vectors with length = 1) and normalizing it will result in vectors biased towards the corners of a cube, rather than uniform distribution