BigInteger: refactor random number generation code somewhat