How to create a vector randomly which keep a fixed distance to the vector zero?

How to create a vector randomly which keep a fixed distance to the vector zero.

code:
randomX = Random.Range(minRandomX,maxRandomX);
randomY = Random.Range(minRandomY,maxRandomY);
randomZ = Mathf.Abs(Mathf.Sqrt(radius * radius - randomX * randomX - randomY * randomY));

This code is running very slowly…

2 Answers

2

Use Random.onUnitSphere. The code is probably slow because of the sqrt.

Thx dude!Cool!