Skip to content

Commit 4c34ceb

Browse files
Ayush1325DhruvaG2000
authored andcommitted
zephyrCommon: Implement random and randomSeed
- Using zephyr stdlib `rand` and `srand` Signed-off-by: Ayush Singh <[email protected]>
1 parent 95e608f commit 4c34ceb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cores/arduino/zephyrCommon.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,21 @@ void detachInterrupt(pin_size_t pinNumber)
331331
{
332332
setInterruptHandler(pinNumber, nullptr);
333333
}
334+
335+
#ifndef CONFIG_MINIMAL_LIBC_RAND
336+
337+
#include <stdlib.h>
338+
339+
void randomSeed(unsigned long seed) {
340+
srand(seed);
341+
}
342+
343+
long random(long min, long max) {
344+
return rand() % (max - min) + min;
345+
}
346+
347+
long random(long max) {
348+
return rand() % max;
349+
}
350+
351+
#endif

0 commit comments

Comments
 (0)