0
$\begingroup$

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

enter image description here

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; } 
  • 0
    @pbs Just thinking about math forced me to realize this could easily be done in a single line. I still have a very similar issue with expressing selecting a random number from a set, so I'll just follow Greg Martin's advice.2012-08-14

1 Answers 1

3

I think this is much easier to state in words than in mathematical notation. "We are given two real numbers min and max between 0 and 1. The function we coded selects a random real number between 0 and 1 as follows: if min < max, then we select a real number uniformly from the interval [min, max); if min > max, we select a real number uniformly from the interval [max, min+1), and then reduce the resulting number modulo 1."