In C ++ / for integers, an integer is obtained. For example, 11/2 leads to 5, not 5.5. Similarly, a / b 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 (if you are not very lucky to get the max number, in which case the result will be one) .
To fix this, you can simply do this:
(double)generator()/generator.max()
source share