I did a little more digging and I think I can give you a more satisfying explanation. I found the Arduino random functions in WMath.cpp:

long random(long howbig)

{

long value;

if (howbig == 0){

return 0;

}

return rand() % howbig;

}

long random(long howsmall, long howbig)

{

if(howsmall >= howbig){

return howsmall;

}

long diff = howbig - howsmall;

return random(diff) + howsmall;

}

These use the rand() function defined in stdlib.h, and rand() returns a signed int. So what this means is that random() will return a number that is always less than or equal to 0x7FFF, even though the definition makes it seem like it can handle longs. This would seem to be a bug in the implementation of random(). If you then look at what this means for random(howsmall, howbig), you see that you are returning a random signed int plus howsmall, which can be a long. The result is exactly what you have already observed.

I think either the random functions should be rewritten to take arguments that are ints, or they should be implemented in a way that actually returns random longs.

- Ben