random() behaving oddly

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?

random() returns an integer, in your usage between -99 and 99. Dividing that return value by the integer 100 results in zero. Declaring "value" to be double does not change how the right hand side of the equation is handled by the compiler.

Try double value = (float) random(-99,99) + ((float) random(-99,99))/100.0;

You use randomSeed()?

How about…

double value = random(-9999,9999) / 100.0;


max - upper bound of the random value, exclusive

How about...

double value = random(-9999,9999) / 100.0;

double value = random(-9999, 10000) * 0.01; // mul is faster than div