float RandomFloat(float a, float b) {
float random = ((float) rand()) / (float) RAND_MAX;
float diff = b - a;
float r = random * diff;
return a + r;
}
This works by returning a
plus something, where something is between 0 and b-a
which makes the end result lie in between a
and b
.