fix sign in code to generate a random signed short (#402)
* fix sign in code to generate a random signed short * Update IdGenerator.scala * Update IdGenerator.scala
This commit is contained in:
parent
ead8c7e889
commit
1281083b32
1 changed files with 4 additions and 2 deletions
|
|
@ -30,7 +30,9 @@ private[pekko] trait IdGenerator {
|
|||
*/
|
||||
@InternalApi
|
||||
private[pekko] object IdGenerator {
|
||||
private val MaxUnsignedShort = 65535
|
||||
// Random.nextInt(bound) generates a random int in the range 0 (inclusive) to bound (exclusive),
|
||||
// so add 1 to Max Unsigned Short (65535)
|
||||
private val UnsignedShortBound = 65536
|
||||
|
||||
sealed trait Policy
|
||||
|
||||
|
|
@ -57,5 +59,5 @@ private[pekko] object IdGenerator {
|
|||
* @return a random sequence of ids for production
|
||||
*/
|
||||
def random(rand: java.util.Random): IdGenerator =
|
||||
() => (rand.nextInt(MaxUnsignedShort) - Short.MinValue).toShort
|
||||
() => (rand.nextInt(UnsignedShortBound) + Short.MinValue).toShort
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue