random numbers

Hello is it possible to get such numbers as 0.125 , 0.25844 , 0.8989
double 0 to 1 but not 0.000011121
errrr... what's the difference? I mean obviously I see that those numbers are different... but I don't see why some are desirable and some are not. Nor do I see how you distinguish between which are desirable.

What do you consider a number you want vs. a number you don't?
Maybe you are right , i have to rest , enough for coding.The much you code , the much you rattle.
Last edited on
To get a number between 0 and 1 as a double, do this:
double d = (double)rand() / (double)RAND_MAX;
http://www.cplusplus.com/reference/cstdlib/RAND_MAX/

When I look at your examples, 0.125 is 1/8, 0.8989 is probably 89/99. Are you looking for random numbers which can be expressed as fractions? If so, find random denominators, and random numerators.

1
2
3
int denom = rand()%DENOM_LIM+1;
int numer = rand()%denom;
double d = (double)numer / (double)denom;

Topic archived. No new replies allowed.