(you could also divide your rand() by (double)RAND_MAX and add 1, but it may not be suitable, since it only generates one of RAND_MAX values, not every possible double: you'd have to call rand() a few more times for each value and do some math if you need full double precision)