Skip to content

Commit 9e6d0ba

Browse files
committed
Random number engine class implementation.
1 parent b9ff039 commit 9e6d0ba

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

include/tomo_rng_engine.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef TOMO_UTIL_H
2+
#define TOMO_UTIL_H
3+
4+
#include <stdint.h>
5+
6+
class TomoRNGEngine final {
7+
public:
8+
static void initializeEngine();
9+
static uint8_t get(uint8_t min, uint8_t max);
10+
};
11+
12+
#endif

src/tomo_rng_engine.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <Arduino.h>
2+
#include <bootloader_random.h>
3+
#include <tomo_rng_engine.h>
4+
5+
void TomoRNGEngine::initializeEngine() {
6+
bootloader_random_enable();
7+
randomSeed(esp_random());
8+
bootloader_random_disable();
9+
}
10+
11+
uint8_t TomoRNGEngine::get(uint8_t min, uint8_t max) {
12+
return (uint8_t) random(min, max);
13+
}

0 commit comments

Comments
 (0)