Rewrite horrible type casting pointer magic with shifts

Why would you generate that random number byte by byte, anyway ?