Random() Maximum

Whoops, looks like you found a bug in the core. We're calling the wrong AVR function, so you'll only get numbers from 0 to 32,767. You could try calling random() twice and putting the number together, e.g.:

(random(32768) << 15) + random(32768);