Scaling Random Bytes to Selected Integer Range
问题 I have a file of true random bytes. I want a function that returns a random integer in the range given by taking a byte from the file and scaling it. (is this the right word?) public int getInt(int l, int h) throws IOException { int m = (h - l) + 1; // number of ranges needed int r = 256 / m; // size of byte range int x = (r * m) - 1; // maximum allowable byte value int b; do { try { // get random byte from file b = ram.readUnsignedByte(); } catch (EOFException e) { // catch EOF, reset