RFR: JDK-8282144 RandomSupport.convertSeedBytesToLongs sign extension overwrites previous bytes
Brian Burkhalter
bpb at openjdk.java.net
Fri Feb 25 20:01:55 UTC 2022
On Thu, 24 Feb 2022 14:47:50 GMT, Jim Laskey <jlaskey at openjdk.org> wrote:
> Class: ./java.base/share/classes/jdk/internal/util/random/RandomSupport.java
> Method: public static long[] convertSeedBytesToLongs(byte[] seed, int n, int z)
>
> The method attempts to create an array of longs by consuming the input bytes most significant bit first. New bytes are appended to the existing long using the OR operator on the signed byte. Due to sign extension this will overwrite all the existing bits from 63 to 8 if the next byte is negative.
test/jdk/java/util/Random/T8282144.java line 39:
> 37: public class T8282144 {
> 38: public static void main(String[] args) {
> 39: RandomGenerator rng = RandomGeneratorFactory.of("L64X128MixRandom").create(42);
Does `rng` always produce the same sequence? If so, then perhaps the seed, `42`, should be a random value that is printed.
test/jdk/java/util/Random/T8282144.java line 52:
> 50: for (int k = 0; k < existing.length; k++) {
> 51: if (existing[k] != testing[k]) {
> 52: throw new RuntimeException("convertSeedBytesToLongs incorrect");
Should `i`, `j`, and `k` be included in the exception message?
-------------
PR: https://git.openjdk.java.net/jdk/pull/7614
More information about the core-libs-dev
mailing list