I'm writing a paper on an application I wrote, and I'm trying to describe mathematically what I did to determine the rotation of an object. What I did is really simple, but my math lags far behind my computer science.
What it does is select a random number between min and max. 0 <= min, max < 1 If min > max, in which case it selects a random number between min and max and subtracts 1 if the number is greater than 1. (i.e. the number under (mod 1))
This is what I'm saying right now:
When determining an orientation, the orientation is selected from the valid orientations, then a random number x is selected such that
Where min is the minimum offset, max is the maximum offset, and 0≤min,max<1. The radian measure of the orientation would be 2πx, and the degree measure would be 360x°.
This is the code in question:
if (min > max) { double d = Utility.r.NextDouble() * (max + 1 - min) + min; if (d >= 1) d -= 1; return d; } else { double d = Utility.r.NextDouble() * (max - min) + min; return d; }