Don't use libc's rand() function, because it is slow. Our own trivial linear congruential generator is good enough for dithering.