The solution you look for is rand() % 7 + 4
which will give you results from range [4, 10]. More general, for given min
and max
to obtain random value from [min, max] you go for rand() % (max - min + 1) + min
1
solved Error in using rand function [closed]