In C++, /
on integer numbers results in an integer number. For example 11 / 2 results in 5, not 5.5. In the same way a / b
is always zero if a < b
.
Your problem is here:
generator()/generator.max()
generator()
and generator.max()
both return integers and of course, generator.max() >= generator()
, so the result is zero (unless you are very lucky to get the max
number in which case the result would be one).
To fix this, you can simply cast it:
(double)generator()/generator.max()