ensure random positive Int

pull/7164/head
Thibault Duplessis 2020-08-21 16:58:19 +02:00
parent bcaa96ab30
commit af1b75ce7d
2 changed files with 2 additions and 1 deletions

View File

@ -12,6 +12,7 @@ object ThreadLocalRandom {
def nextFloat(): Float = current.nextFloat()
def nextInt(): Int = current.nextInt()
def nextInt(n: Int): Int = current.nextInt(n)
def nextPositiveInt(): Int = current.nextInt(Int.MaxValue)
def nextLong(): Long = current.nextLong()
def nextChar(): Char = {
val i = nextInt(62)

View File

@ -38,7 +38,7 @@ final class RemoteSocket(
private val requests = new ConcurrentHashMap[Int, Promise[String]](32)
def request[R](sendReq: Int => Unit, readRes: String => R): Fu[R] = {
val id = Math.abs(lila.common.ThreadLocalRandom.nextInt())
val id = lila.common.ThreadLocalRandom.nextPositiveInt()
sendReq(id)
val promise = Promise[String]()
requests.put(id, promise)