Languages
[Edit]
EN

Java - generate array of random bytes

2 points
Created by:
JustMike
26120

1. ThreadLocalRandom.nextBytes

byte[] arr = new byte[10];
ThreadLocalRandom.current().nextBytes(arr);

// [-62, -75, 50, -127, 86, -21, 84, 53, 34, -45]
System.out.println(Arrays.toString(arr));


2. Random.nextBytes

byte[] arr = new byte[10];
new Random().nextBytes(arr);

// [-50, -67, 109, -126, 24, 118, -121, -77, 15, -97]
System.out.println(Arrays.toString(arr));


References

ThreadLocalRandom - Java docs
Random - Java docs

Java - random numbers

Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join