I'm making an asteroid belt for my project it consists of a lot of objects that are random put 300 pixels from the sun then add Math.random() * 300 so that it will randomly be between 300-600 distance away from the sun. However I wanted it to be less far away and more nearer to the sun, so I did the following:
300 + Math.random()*300*Math.random()
Therefore it is less likely to be nearer to 600 and more likely to be nearer to 300.
What I want now is for there to be lots in the middle of the range 300-600 and less near the sun and less far away but I can't get my head around how to do it.
Any help would be appreciated, cheers.
EDIT:
Wow, the second I stopped writing I figured it out.
if (Math.random() < 0.5)
{
450 + Math.random() * 150 * Math.random()
}
else
{
450 - Math.random() * 150 * Math.random()
}
300 + Math.random()*300*Math.random()
Therefore it is less likely to be nearer to 600 and more likely to be nearer to 300.
What I want now is for there to be lots in the middle of the range 300-600 and less near the sun and less far away but I can't get my head around how to do it.
Any help would be appreciated, cheers.
EDIT:
Wow, the second I stopped writing I figured it out.
if (Math.random() < 0.5)
{
450 + Math.random() * 150 * Math.random()
}
else
{
450 - Math.random() * 150 * Math.random()
}
Last edited: