drand48() returns a double , while rand() returns int .
In addition, drand48() returns a value that is distributed between [0.0, 1.0) , so your formula should change:
double x = drand48() * 1000.0 + 1;
or
double x = (int)(drand48() * 1000.0) + 1;
You can either scale the result of drand48() as described above, or use lrand48() with an existing formula.
source share