Francesco Bonizzi
Francesco Bonizzi

Reputation: 5302

How can I generate a random angle in radians in this range?

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

Upvotes: 0

Views: 3508

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500035

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);

Upvotes: 5

Related Questions