That doesn’t exclude -3.0
, because rand()
is uniform in [0,1)
.
See this answer: How to create a random Uniform Distribution between (but excluding) 0 and 10? - #21 by Elrod, which leads to the analogous solution:
prevfloat(6.0) * (1 - rand()) - 3
for generating random numbers uniformly for floating-point values in the open interval (-3,3)
.