import java.util.random.RandomGenerator;
import java.util.random.RandomGeneratorFactory;

public class RandomSupport {
    private static final char[] HEX_DIGITS =
            {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    public static long[] convertSeedBytesToLongs(byte[] seed, int n, int z) {
        final long[] result = new long[n];
        final int m = Math.min(seed.length, n << 3);
        // Distribute seed bytes into the words to be formed.
        for (int j = 0; j < m; j++) {
            // Sign extension bug
            result[j >> 3] = (result[j >> 3] << 8) | seed[j];
        }
        // Filling the rest of the long[] has been removed for brevity.
        // It only matters if the bytes are shorter than the desired length of long[].
        return result;
    }

    public static long[] convertSeedBytesToLongsFixed(byte[] seed, int n, int z) {
        final long[] result = new long[n];
        final int m = Math.min(seed.length, n << 3);
        // Distribute seed bytes into the words to be formed.
        for (int j = 0; j < m; j++) {
            result[j >> 3] = (result[j >> 3] << 8) | (seed[j] & 0xff);
        }
        return result;
    }

    public static void main(String[] args) {
        RandomGenerator rng = RandomGeneratorFactory.of("L64X128MixRandom").create(42);
        for (int i = 1; i < 8; i++) {
            byte[] seed = new byte[i];
            for (int j = 0; j < 10; j++) {
                rng.nextBytes(seed);

                for (byte b : seed) {
                    System.out.printf("%c%c", HEX_DIGITS[(b & 0xf0) >> 4], HEX_DIGITS[b & 0xf]);
                }
                System.out.printf(" %-16s %-16s%n",
                        Long.toHexString(convertSeedBytesToLongs(seed, 1, 1)[0]),
                        Long.toHexString(convertSeedBytesToLongsFixed(seed, 1, 1)[0]));
            }
        }
    }
}