I am working on a DRO project for my drill press and to test that i got my code right i wanted random input in the range of -99.99 to 99.99. In order to do this i used the random(min, max) function and this was my first attempt:
double value = random(-99,99) + random(-99,99)/100;
Looks pretty straight forward right? Oddly enough this always resulted in values where the decimal values were all zeroes.
in the end i had to resort to this to get the result i wanted:
double A = random(-99,99); double B = random(-99,99); B = B /100; double value = A + B;
Any idea why the two code snippets behave so differently?