/** * Generates random bytes and places them into a user-supplied * byte array. The number of random bytes produced is equal to * the length of the byte array. * <p> * The default implementation fills the array with bytes extracted from * random integers generated using {@link #nextInt}.</p> * * @param bytes the non-null byte array in which to put the * random bytes */ public void nextBytes(byte[] bytes) { int bytesOut = 0; while (bytesOut < bytes.length) { int randInt = nextInt(); for (int i = 0; i < 3; i++) { if ( i > 0) { randInt >>= 8; } bytes[bytesOut++] = (byte) randInt; if (bytesOut == bytes.length) { return; } } } }
/** * Generates random bytes and places them into a user-supplied * byte array. The number of random bytes produced is equal to * the length of the byte array. * <p> * The default implementation fills the array with bytes extracted from * random integers generated using {@link #nextInt}.</p> * * @param bytes the non-null byte array in which to put the * random bytes */ public void nextBytes(byte[] bytes) { int bytesOut = 0; while (bytesOut < bytes.length) { int randInt = nextInt(); for (int i = 0; i < 3; i++) { if ( i > 0) { randInt >>= 8; } bytes[bytesOut++] = (byte) randInt; if (bytesOut == bytes.length) { return; } } } }
/** * Generates random bytes and places them into a user-supplied * byte array. The number of random bytes produced is equal to * the length of the byte array. * <p> * The default implementation fills the array with bytes extracted from * random integers generated using {@link #nextInt}.</p> * * @param bytes the non-null byte array in which to put the * random bytes */ public void nextBytes(byte[] bytes) { int bytesOut = 0; while (bytesOut < bytes.length) { int randInt = nextInt(); for (int i = 0; i < 3; i++) { if ( i > 0) { randInt >>= 8; } bytes[bytesOut++] = (byte) randInt; if (bytesOut == bytes.length) { return; } } } }