Hello there,
To get to the point, I have this function:
where ACCURACY equals 1000Code:double fractNum(int limit) { int x = rand() % (limit + 1); double y = rand() % ACCURACY; y/= ACCURACY; y+=x; return y; }
srand is seeded like this:
the function is called like this:Code:time_t seconds; time(&seconds); srand((unsigned int) seconds);
where HIGHT and LENGTH equal 10, x is being incremented by a loop, and object is a struct, but that doesn't really matter.Code:object[x].realX = fractNum(HIGHT); object[x].realY = fractNum(LENGTH);
What this should do is assign a real value to realX/Y, between 0.000 and 9.999. The problem is, instead I get gross values like -282433580....goes on for around 30 digits plus a couple after the decimal point. I have no idea what's going on...the problem seems to be in the random generator, as far as I could tell....anyone see the problem I've missed? :-)
Thanks,
G4B3



LinkBack URL
About LinkBacks




