From c843680e07a0e41f2666ad5d7b7901255f05c001 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 18 Jul 2021 10:19:07 +0200 Subject: [PATCH] [PHY] Fixed negative random numbers (#328) --- src/protocols/PhysicalLayer/PhysicalLayer.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/protocols/PhysicalLayer/PhysicalLayer.cpp b/src/protocols/PhysicalLayer/PhysicalLayer.cpp index c81d306a..d32670a7 100644 --- a/src/protocols/PhysicalLayer/PhysicalLayer.cpp +++ b/src/protocols/PhysicalLayer/PhysicalLayer.cpp @@ -159,6 +159,10 @@ int32_t PhysicalLayer::random(int32_t max) { // create 32-bit TRNG number int32_t randNum = ((int32_t)randBuff[0] << 24) | ((int32_t)randBuff[1] << 16) | ((int32_t)randBuff[2] << 8) | ((int32_t)randBuff[3]); + if(randNum < 0) { + randNum *= -1; + } + RADIOLIB_DEBUG_PRINTLN(randNum); return(randNum % max); }