Removed shitty random utilities

This commit is contained in:
2021-09-05 21:09:19 +02:00
parent 8e447f5cd5
commit b0223be116
2 changed files with 0 additions and 44 deletions

View File

@ -115,10 +115,6 @@ typedef bool boolean;
typedef uint8_t byte;
typedef unsigned int word;
#ifdef __cplusplus
long random(long, long);
#endif
void randomSeed(unsigned long);
long map(long, long, long, long, long);
#ifdef __cplusplus
@ -155,8 +151,6 @@ uint16_t makeWord(byte h, byte l);
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
// WMath prototypes
long random(long);
#endif /* __cplusplus */
#define _min(a,b) ((a)<(b)?(a):(b))

View File

@ -24,47 +24,9 @@
*/
extern "C" {
#include <stdlib.h>
#include "esp_system.h"
}
void randomSeed(unsigned long seed)
{
if(seed != 0) {
srand(seed);
}
}
long random(long howbig)
{
uint32_t x = esp_random();
uint64_t m = uint64_t(x) * uint64_t(howbig);
uint32_t l = uint32_t(m);
if (l < howbig) {
uint32_t t = -howbig;
if (t >= howbig) {
t -= howbig;
if (t >= howbig)
t %= howbig;
}
while (l < t) {
x = esp_random();
m = uint64_t(x) * uint64_t(howbig);
l = uint32_t(m);
}
}
return m >> 32;
}
long random(long howsmall, long howbig)
{
if(howsmall >= howbig) {
return howsmall;
}
long diff = howbig - howsmall;
return random(diff) + howsmall;
}
long map(long x, long in_min, long in_max, long out_min, long out_max) {
const long dividend = out_max - out_min;
const long divisor = in_max - in_min;