Generating a random point on the unit circle

2.5k Views Asked by At

I'm trying to figure out a way to generate a random point on the unit circle in an application I am developing (I'm a programmer).

So far I have the following (in pseudo-code), where Z is a random number between 0.0 and 1.0:

theta = (2.0 * PI) * Z

2DVector.x = cos(theta)
2DVector.y = sin(theta)

result: 2DVector

I know that it's wrong, as I'm getting nothing but massive x values and tiny y values. But I'm not familiar enough with the unit circle mathematics to know where I'm going wrong!

1

There are 1 best solutions below

5
On BEST ANSWER

The example I provided works fine, so long as it's implemented properly.