Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community of people that helps each other.

If you think you have some skills to help others

help someone and become a part of our community - List Q & A

Java - generate array of random bytes

0 contributions
2 points

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

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more