Question

What I do to generate a random angle is this:

float rand_angle = (float)random_.NextDouble() * MathHelper.TwoPi;

But I want to generate a random angle from range [a;b], excluding everything in the middle.

Ho Can I do it?

Example

Was it helpful?

Solution

But I want to generate a random angle from range [a;b], excluding everything in the middle.

Assuming b is greater than a, that's just a matter of getting a value in the range [0, b - a) and then adding a:

float randomAngle = (float) (random.NextDouble() * (b - a) + a);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top