Skip to content

Commit 34c9feb

Browse files
committed
Use ThreadLocalRandom.current()
1 parent 4534076 commit 34c9feb

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/test/java/org/apache/commons/codec/binary/HexTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.nio.charset.UnsupportedCharsetException;
3131
import java.util.Arrays;
3232
import java.util.Random;
33-
33+
import java.util.concurrent.ThreadLocalRandom;
3434
import org.apache.commons.codec.DecoderException;
3535
import org.apache.commons.codec.EncoderException;
3636
import org.junit.Assert;
@@ -422,12 +422,11 @@ public void testEncodeClassCastException() {
422422

423423
@Test
424424
public void testEncodeDecodeHexCharArrayRandom() throws DecoderException, EncoderException {
425-
final Random random = new Random();
426425

427426
final Hex hex = new Hex();
428427
for (int i = 5; i > 0; i--) {
429-
final byte[] data = new byte[random.nextInt(10000) + 1];
430-
random.nextBytes(data);
428+
final byte[] data = new byte[ThreadLocalRandom.current().nextInt(10000) + 1];
429+
ThreadLocalRandom.current().nextBytes(data);
431430

432431
// static API
433432
final char[] encodedChars = Hex.encodeHex(data);
@@ -455,10 +454,9 @@ public void testEncodeDecodeHexCharArrayRandom() throws DecoderException, Encode
455454

456455
@Test
457456
public void testEncodeDecodeHexCharArrayRandomToOutput() throws DecoderException, EncoderException {
458-
final Random random = new Random();
459457
for (int i = 5; i > 0; i--) {
460-
final byte[] data = new byte[random.nextInt(10000) + 1];
461-
random.nextBytes(data);
458+
final byte[] data = new byte[ThreadLocalRandom.current().nextInt(10000) + 1];
459+
ThreadLocalRandom.current().nextBytes(data);
462460

463461
// lower-case
464462
final char[] lowerEncodedChars = new char[data.length * 2];

0 commit comments

Comments
 (0)