- Home /

# Random.rotationUniform clarification

In the doc it says:

*Random.rotation Returns a random rotation (Read Only).*

*Random.rotationUniform Returns a random rotation with uniform distribution(Read Only).*

I'm not sure at 100% that I understand correctly this property. If I generate 10 random rotation with Random.rotation I'll get 10 totally random rotation and it's technically possible (but improbable) that I can get almost the same rotation twice.

If I use Random.rotationUniform, I'll have 10 really distinct rotation.

Right or wrong?

**EDIT: My question was probably not enough clear (sorry, english is my second language). You basically said the same thing has I thought.I run some test to see the difference graphically, but I can't see any difference. I generate random rotation with both method for a vector and the randomUniform is not more uniform. So I'm a bit confuse about this property**

On the left is random.rotation and the right is random.rotationUniform

@$$anonymous$$arkPixel - great way to sort this out. Go to 5,000 and then inspect the poles. Also explicitly set the seed and run both with the same seed. It may be that under the hood '.random' and '.randomUniform' are the same thing now. But in generating random values, when you see the word 'Uniform' it will refer to an equal probability over a range.

$$anonymous$$e seed, different result, it's not the same function. Even at 5000 and 1000 I barely see the difference

Nice job. It is the kind of thing I tend to do when I have a question about Unity.

[Begin Conjecture]

There are good reasons for wanting a Uniform distribution. The original developer who wrote Random.rotation fully intended it to be uniform, but at some point someone figure out that there is a bug/flaw. That, however slight, the distribution is not uniform. The team cannot just go in and fix the bug. There is code that depends on the original implementation. What if there exists code for saving a game level saved not the individual positions, but the seed and regenerated the positions using the seed and Random.rotation? So to patch the bug and have a truly uniform distribution for future development, they introduced random.rotationUniform. I don't remember this variable from Unity 3.x.

[End Conjecture]

Hey guys, maybe it's my eyes, but I do see some clustering in the the left samples of 50, 10, 500, and 1000. It's not great but I do see some high and low density areas... It seems to me that because we see 3D models of the spheres using 2D pictures it is rather difficult to distinguish the exact location depth-wise of particular points. And this becomes even more and more difficult as the number of points increases.

So, all in all, if there was a small bug of a statistical nature in the original algorithm, I wouldn't be surprised that it's not very easy to observe in the samples @$$anonymous$$arkPixel made. Only if the original bug was big enough, the high density clusters and low density gaps would be easily observable. But come to think of it, if that was the case, then the bug would probably not exist at all, because it would be evident to the developer from sample outputs that something is wrong.

Nice work @$$anonymous$$arkPixel in pointing this out, and thanks @robertbu for the explanation!

**Answer** by robertbu
·
Oct 14, 2013 at 07:06 PM

Wrong. 'Random.rotationUniform' means that all possible rotations have equal probability of occurring. I expect if you tested the original Random.rotation you would find some clustering in the rotation. That is if you use the rotation to rotate a vector and then plotted the tip of each vector, Random.rotationUniform would produce a sphere where the points were generally uniformly distributed. With the Random.rotaition you'd likely see some clusters of points.

@pako - Don't be sorry. Multiple answers are a good thing. And even if you see an answer, if you think you have a better one, go for it.

**Answer** by sleiN13
·
Aug 26, 2015 at 09:26 PM

I would assume that the first implementation just generates three random values for the Yaw, Pitch and Roll of the rotation. While this seem random there are multiple combinations of Yaw, Pitch and Roll that will represent the same direction. This means those directions have a increased chance to be generated.

What I'm wondering is how they solved this to make the distribution truly uniform.

**Answer** by NovHak
·
Nov 16, 2018 at 04:20 PM

I'm late here, but the problem doesn't seem to have been addressed after more than five years now. I mean, nothing official, only guesses.

I don't have much more to say than @robertbu. As he said, `Random.rotationUniform`

doesn't guarantee that different rotations will be drawn, but if I'm correct, does give rotations uniformly distributed on the hypersphere. So one would say, why use `Random.rotation`

? It's because `rotationUniform`

is likely more demanding, hence `Random.rotation`

sacrifices uniformity to performance.

Problem is it's on a 4 dimensional hypersphere, hence it could be difficult to notice visually. The clusters are probably around the 16 projections of the corners of the unit hypercube on the hypersphere. After some thought, I suppose it could still be seen on a projection of the w = 0 hyperplan (or x = 0, or y = 0, or z = 0), where the clusters would be around the 8 projections of the cube corners on the sphere.

But that's my idea of it and I can't say for sure...

### 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.

### Follow this Question

### Related Questions

Quaternions local/world 1 Answer

What is the rotation equivalent of InverseTransformPoint? 3 Answers

Adding Rotation to a Gameobject 1 Answer