- Home /

# My interpretation of Random.rotation and Random.rotationUniform. Right or wrong ?

Dear forum readers,

For modding reasons, I'm rewriting Unity's UnityEngine.Random class. I think I got everything, except maybe the Random.rotation and Random.rotationUniform properties.

Do these rewrites seem legit to you ? The only difference between the two being in the do-while condition.

```
public sealed partial class Random
{
public static Quaternion rotation
{
get
{
float norm, w, x, y, z;
do
{
w = Range(-1f, 1f);
x = Range(-1f, 1f);
y = Range(-1f, 1f);
z = Range(-1f, 1f);
norm = w * w + x * x + y * y + z * z;
}
while (norm == 0f);
norm = (float)System.Math.Sqrt(norm);
Quaternion quat;
quat.w = w / norm;
quat.x = x / norm;
quat.y = y / norm;
quat.z = z / norm;
return quat;
}
}
public static Quaternion rotationUniform
{
get
{
float norm, w, x, y, z;
do
{
w = Range(-1f, 1f);
x = Range(-1f, 1f);
y = Range(-1f, 1f);
z = Range(-1f, 1f);
norm = w * w + x * x + y * y + z * z;
}
while ((norm > 1f) || (norm == 0f));
norm = (float)System.Math.Sqrt(norm);
Quaternion quat;
quat.w = w / norm;
quat.x = x / norm;
quat.y = y / norm;
quat.z = z / norm;
return quat;
}
}
}
```

Comment

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.