Skip to content

Commit

Permalink
zephyrCommon: Implement random and randomSeed
Browse files Browse the repository at this point in the history
- Using zephyr random api
- Using a stub for randomSeed since it is not present in Zephyr

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
  • Loading branch information
Ayush1325 committed Jun 7, 2024
1 parent 347a80d commit a4780cf
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cores/arduino/zephyrCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,23 @@ void detachInterrupt(pin_size_t pinNumber)
{
setInterruptHandler(pinNumber, nullptr);
}

#ifndef CONFIG_RNG_GENERATOR_CHOICE

#include <zephyr/random/random.h>

void randomSeed(unsigned long) {}

long random(long min, long max) {
long temp;

sys_rand_get(&temp, sizeof(temp));

return temp % (max - min) + min;
}

long random(long max) {
return random(0, max);
}

#endif

0 comments on commit a4780cf

Please sign in to comment.