src/java.base/share/classes/java/util/SplittableRandom.java
changeset 47342 bffcbf07ea88
parent 47216 71c04702a3d5
child 52957 c7c285b0b640
--- a/src/java.base/share/classes/java/util/SplittableRandom.java	Fri Oct 13 18:12:54 2017 -0700
+++ b/src/java.base/share/classes/java/util/SplittableRandom.java	Fri Oct 13 18:19:18 2017 -0700
@@ -399,6 +399,26 @@
     }
 
     /**
+     * Fills a user-supplied byte array with generated pseudorandom bytes.
+     *
+     * @param  bytes the byte array to fill with pseudorandom bytes
+     * @throws NullPointerException if bytes is null
+     * @since  10
+     */
+    public void nextBytes(byte[] bytes) {
+        int i = 0;
+        int len = bytes.length;
+        for (int words = len >> 3; words--> 0; ) {
+            long rnd = nextLong();
+            for (int n = 8; n--> 0; rnd >>>= Byte.SIZE)
+                bytes[i++] = (byte)rnd;
+        }
+        if (i < len)
+            for (long rnd = nextLong(); i < len; rnd >>>= Byte.SIZE)
+                bytes[i++] = (byte)rnd;
+    }
+
+    /**
      * Returns a pseudorandom {@code int} value.
      *
      * @return a pseudorandom {@code int} value