You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "pjfanning (via GitHub)" <gi...@apache.org> on 2023/06/15 23:01:20 UTC

[GitHub] [incubator-pekko] pjfanning opened a new pull request, #402: fix sign in code to generate a random signed short

pjfanning opened a new pull request, #402:
URL: https://github.com/apache/incubator-pekko/pull/402

   see https://github.com/apache/incubator-pekko/pull/401#discussion_r1231609526


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] He-Pin commented on a diff in pull request #402: fix sign in code to generate a random signed short

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #402:
URL: https://github.com/apache/incubator-pekko/pull/402#discussion_r1231719999


##########
actor/src/main/scala/org/apache/pekko/io/dns/IdGenerator.scala:
##########
@@ -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(SignedShortBound) + Short.MinValue).toShort

Review Comment:
   `rand.nextInt(65535 -1) + 1`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] pjfanning commented on a diff in pull request #402: fix sign in code to generate a random signed short

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #402:
URL: https://github.com/apache/incubator-pekko/pull/402#discussion_r1231948876


##########
actor/src/main/scala/org/apache/pekko/io/dns/IdGenerator.scala:
##########
@@ -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 SignedShortBound = 65536

Review Comment:
   thanks - sorted that now



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] He-Pin commented on a diff in pull request #402: fix sign in code to generate a random signed short

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #402:
URL: https://github.com/apache/incubator-pekko/pull/402#discussion_r1231719999


##########
actor/src/main/scala/org/apache/pekko/io/dns/IdGenerator.scala:
##########
@@ -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(SignedShortBound) + Short.MinValue).toShort

Review Comment:
   `rand.nextInt(65535 - 1) + 1`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] nvollmar commented on a diff in pull request #402: fix sign in code to generate a random signed short

Posted by "nvollmar (via GitHub)" <gi...@apache.org>.
nvollmar commented on code in PR #402:
URL: https://github.com/apache/incubator-pekko/pull/402#discussion_r1231865421


##########
actor/src/main/scala/org/apache/pekko/io/dns/IdGenerator.scala:
##########
@@ -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 SignedShortBound = 65536

Review Comment:
   Wouldn't that be `UnsignedShortBound`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] pjfanning merged pull request #402: fix sign in code to generate a random signed short

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #402:
URL: https://github.com/apache/incubator-pekko/pull/402


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] pjfanning commented on a diff in pull request #402: fix sign in code to generate a random signed short

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #402:
URL: https://github.com/apache/incubator-pekko/pull/402#discussion_r1231952800


##########
actor/src/main/scala/org/apache/pekko/io/dns/IdGenerator.scala:
##########
@@ -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(SignedShortBound) + Short.MinValue).toShort

Review Comment:
   0 is valid. so `rand.nextInt(65536) will give us a response int between 0 and 65535 - ie 65536 possible answers. This is what I'm looking for.
   
   65535 + Short.MIN_VALUE (-32768) is 32767 (which is Short.MAX_VALUE).
   
   0 + Short.MIN_VALUE is -32768 (Short.MIN_VALUE).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] nvollmar commented on a diff in pull request #402: fix sign in code to generate a random signed short

Posted by "nvollmar (via GitHub)" <gi...@apache.org>.
nvollmar commented on code in PR #402:
URL: https://github.com/apache/incubator-pekko/pull/402#discussion_r1231865421


##########
actor/src/main/scala/org/apache/pekko/io/dns/IdGenerator.scala:
##########
@@ -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 SignedShortBound = 65536

Review Comment:
   Wouldn't that be `UnsignedShortBound`?
   I'd leave the constant as `MaxUnsignedShort = 65535` and then call `rand.nextInt(MaxUnsignedShort + 1)` and leave the comment there.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] nvollmar commented on a diff in pull request #402: fix sign in code to generate a random signed short

Posted by "nvollmar (via GitHub)" <gi...@apache.org>.
nvollmar commented on code in PR #402:
URL: https://github.com/apache/incubator-pekko/pull/402#discussion_r1231865421


##########
actor/src/main/scala/org/apache/pekko/io/dns/IdGenerator.scala:
##########
@@ -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 SignedShortBound = 65536

Review Comment:
   Wouldn't that be `UnsignedShortBound`?
   I'd leave the constant as `MaxUnsignedShort = 65535` and then call `rand.nextInt(UnsignedShortBound + 1)` and leave the comment there.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org