From 282d95f48e833cd665db0b9ab5308a7fc430bafd Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Fri, 7 Jun 2024 19:57:56 +0530 Subject: [PATCH] zephyrCommon: Implement random and randomSeed - Using zephyr stdlib `rand` and `srand` Signed-off-by: Ayush Singh --- cores/arduino/zephyrCommon.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cores/arduino/zephyrCommon.cpp b/cores/arduino/zephyrCommon.cpp index 219d3cda..f89f03f9 100644 --- a/cores/arduino/zephyrCommon.cpp +++ b/cores/arduino/zephyrCommon.cpp @@ -328,3 +328,21 @@ void detachInterrupt(pin_size_t pinNumber) { setInterruptHandler(pinNumber, nullptr); } + +#ifndef CONFIG_MINIMAL_LIBC_RAND + +#include + +void randomSeed(unsigned long seed) { + srand(seed); +} + +long random(long min, long max) { + return rand() % (max - min) + min; +} + +long random(long max) { + return rand() % max; +} + +#endif