I want to make a bunch of objects travel in random directions. You'd think that y_velocity=Math.sqrt(1-Math.pow(x_velocity,2)), right? But squaring and square rooting numbers leads to the loss of some really important information and I end up with a not so uniform distribution:

Is there any way that I can a uniform distribution? So far I have this, were sign(double a) just gives a random sign and object is an array list of objects:

Code: Select all

` void ring()`

{

for(int a=0;a<1000;a++)

{

object b=new object(width/2,height/2);

object.add(b);

b.yv=sign(Math.sqrt(1-Math.pow(b.xv=sign(random.nextDouble()),2)));

}

}