Lutz wrote:Try to take away statements in your program, gradually simplifying it until you find the smallest version which can reproduce the problem on 9.3.14/15, without the "winclip -c -w" part and perhaps setting 'input' to some constant. This way I can try to reproduce the problem too.
I have looked into your C source instead, and seems like I have found a bug. In fact, two bugs. You treat RAND_MAX constant as exclusive, while in C standard library it is inclusive. C 'rand' function
can yield RAND_MAX, and sometimes
does it. This is hard to notice when your RAND_MAX is 2147483647, but easy when it is 32767 as in MinGW. See this:
Code: Select all
RANDOMIZE:
for(i = 0; i < (length - 1); i++)
{
scale = length - i;
j = i + getRandom(0.0, scale, DIST_RANDOM);
cell = vector[i];
vector[i] = vector[j];
vector[j] = cell;
}
, where appropriate part of getRandom is:
Code: Select all
if(type == DIST_RANDOM)
{
randnum = random();
return(scale * randnum/MY_RAND_MAX + offset);
}
If random() yielded RAND_MAX, then getRandom will yield scale, j became equal to length, and the code tries to access "after the last" element of the vector. Length of my input is near 725, so chances to hit this are near 32768/725 = 45. My estimate "one out of twenty" was twice optimistic. ;-)
I've pushed into message size limit, to be continued...