Skip to content

Commit 282d95f

Browse files
committed
zephyrCommon: Implement random and randomSeed
- Using zephyr stdlib `rand` and `srand` Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
1 parent 347a80d commit 282d95f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cores/arduino/zephyrCommon.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,21 @@ void detachInterrupt(pin_size_t pinNumber)
328328
{
329329
setInterruptHandler(pinNumber, nullptr);
330330
}
331+
332+
#ifndef CONFIG_MINIMAL_LIBC_RAND
333+
334+
#include <stdlib.h>
335+
336+
void randomSeed(unsigned long seed) {
337+
srand(seed);
338+
}
339+
340+
long random(long min, long max) {
341+
return rand() % (max - min) + min;
342+
}
343+
344+
long random(long max) {
345+
return rand() % max;
346+
}
347+
348+
#endif

0 commit comments

Comments
 (0)