This is an automated email from the ASF dual-hosted git repository.
He-Pin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/main by this push:
new f571b64f78 refactor: use RandomGenerator interface instead of
java.util.Random (#3153)
f571b64f78 is described below
commit f571b64f785b0ce1e5f79a4a21e3227392dbbc79
Author: He-Pin(kerr) <[email protected]>
AuthorDate: Tue Jun 23 17:16:05 2026 +0800
refactor: use RandomGenerator interface instead of java.util.Random (#3153)
Motivation:
IdGenerator uses java.util.Random as the parameter type for random
number generators. JDK 17 introduced java.util.random.RandomGenerator
as a common interface implemented by Random, ThreadLocalRandom,
SecureRandom, and SplittableRandom.
Modification:
Change the parameter type from java.util.Random to RandomGenerator
in the random() factory method and EnhancedDoubleHashGenerator
constructor. This allows any RandomGenerator implementation to be
used, including SplittableRandom.
Result:
More flexible random generator API. All existing callers
(ThreadLocalRandom.current(), new SecureRandom()) already implement
RandomGenerator, so this is source and binary compatible.
Tests:
sbt "actor/compile" — passed
References:
Refs #3136
---
actor/src/main/scala/org/apache/pekko/io/dns/IdGenerator.scala | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/actor/src/main/scala/org/apache/pekko/io/dns/IdGenerator.scala
b/actor/src/main/scala/org/apache/pekko/io/dns/IdGenerator.scala
index 598d41dafa..17831760bd 100644
--- a/actor/src/main/scala/org/apache/pekko/io/dns/IdGenerator.scala
+++ b/actor/src/main/scala/org/apache/pekko/io/dns/IdGenerator.scala
@@ -18,8 +18,8 @@
package org.apache.pekko.io.dns
import java.security.SecureRandom
-import java.util.Random
import java.util.concurrent.ThreadLocalRandom
+import java.util.random.RandomGenerator
import org.apache.pekko.annotation.InternalApi
@@ -62,10 +62,10 @@ private[pekko] object IdGenerator {
/**
* @return a random sequence of ids for production
*/
- def random(rand: java.util.Random): IdGenerator =
+ def random(rand: RandomGenerator): IdGenerator =
() => (rand.nextInt(UnsignedShortBound) + Short.MinValue).toShort
- private[pekko] class EnhancedDoubleHashGenerator(seed: Random) extends
IdGenerator {
+ private[pekko] class EnhancedDoubleHashGenerator(seed: RandomGenerator)
extends IdGenerator {
/**
* An efficient thread safe generator of pseudo random shorts based on
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]