Incorrect calculation of random ints

Incorrect calculation of random integers was causing random overflows
and crashes, particularly when a Spectre was being rendered.