Languages
[Edit]
EN

Java - generate array of random bytes

2 points
Created by:
Huzaifa-Ball
475

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

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java - random numbers

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join